1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| Public Sub copyFile(ByVal copyFilePath As String)
Dim asyncCall As AsyncCallback
Dim asyncCallWrite As AsyncCallback
If File.Exists(copyFilePath) Then
File.Delete(copyFilePath)
End If
Try
' Instantiation des flux
_fileStreamOrignal = New FileStream(Me._completeFilePath, FileMode.Open, FileAccess.Read)
_fileStreamDestination = New FileStream(copyFilePath, FileMode.Create, FileAccess.Write)
Dim buffer(_fileStreamOrignal.Length) As Byte
' Instantiation des AsyncCallback
asyncCall = New AsyncCallback(AddressOf ReadOnComplete)
asyncCallWrite = New AsyncCallback(AddressOf WriteOnComplete)
'Positionner le flux au début de fichier
_fileStreamOrignal.Seek(0, SeekOrigin.Begin)
'Lecture puis écriture asynchrone
_fileStreamOrignal.BeginRead(buffer, 0, buffer.Length, asyncCall, 0)
_fileStreamDestination.BeginWrite(buffer, 0, buffer.Length, asyncCallWrite, 0)
Catch ex As Exception
End Try
End Sub
Private Sub ReadOnComplete(ByVal asyncResult As IAsyncResult)
Dim bytesRead As Integer
bytesRead = _fileStreamOrignal.EndRead(asyncResult)
_fileStreamOrignal.Close()
End Sub
Private Sub WriteOnComplete(ByVal asyncResult As IAsyncResult)
_fileStreamDestination.EndWrite(asyncResult)
_fileStreamDestination.Close()
End Sub |
Partager