Ну никак я не пойму как этим пользоваться, так тоже не работает:
- Код: Выделить всё
Private Declare Auto Function CopyFileEx Lib "kernel32.dll" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal lpProgressRoutine As CopyProgressRoutine, ByVal lpData As Int32, ByVal lpBool As Int32, ByVal dwCopyFlags As Int32) As Int32
Private Delegate Function CopyProgressRoutine(ByVal totalFileSize As Int64, ByVal totalBytesTransferred As Int64, ByVal streamSize As Int64, ByVal streamBytesTransferred As Int64, ByVal dwStreamNumber As Int32, ByVal dwCallbackReason As Int32, ByVal hSourceFile As Int32, ByVal hDestinationFile As Int32, ByVal lpData As Int32) As Int32
Const StartFile As String = "C:\1.avi"
Const DestFile As String = "C:\2.avi"
Dim PercentComplit As Long
Dim StartFileSize, DestFileSize As Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click
lbStatus.Text = "Идет копирование"
BckgWorker.RunWorkerAsync()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
txtStart.Text = StartFile
txtDest.Text = DestFile
lbStatus.Text = "Для начала копирования нажмите Start"
StartFileSize = My.Computer.FileSystem.GetFileInfo(StartFile).Length
lbStartFileSize.Text = StartFileSize
If My.Computer.FileSystem.FileExists(DestFile) Then
DestFileSize = My.Computer.FileSystem.GetFileInfo(DestFile).Length
Else
DestFileSize = 0
End If
End Sub
Private Sub BckgWorker_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BckgWorker.DoWork
Dim cpr As New CopyProgressRoutine(AddressOf CopyProgress)
CopyFileEx("C:\1.avi", "C:\2.avi", cpr, 0, 0, 0)
BckgWorker.ReportProgress(PercentComplit)
End Sub
Private Sub BckgWorker_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BckgWorker.ProgressChanged
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub BckgWorker_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BckgWorker.RunWorkerCompleted
lbStatus.Text = "Копирование завершено"
End Sub
Private Function CopyProgress(ByVal totalFileSize As Int64, ByVal totalBytesTransferred As Int64, ByVal streamSize As Int64, ByVal streamBytesTransferred As Int64, ByVal dwStreamNumber As Int32, ByVal dwCallbackReason As Int32, ByVal hSourceFile As Int32, ByVal hDestinationFile As Int32, ByVal lpData As Int32) As Int32
PercentComplit = Convert.ToInt32(totalBytesTransferred / totalFileSize * 100)
End Function
Мне кажется BckgWorker.ReportProgress срабатывает, но только один раз и когда файл уже скопирован. Как его постоянно-то вызывать ?