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
| Public Class frmMain
Private WithEvents oDll As dll
Private iLocalSize As Long
Private iByteDone = 0
Private Delegate Sub ProgressBarDelegateHandler(ByVal [step] As Long)
Private ProgressBarDelegate As ProgressBarDelegateHandler
Private t As New Thread(New ThreadStart(AddressOf ThreadProcess))
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
oDll = New dll
'[..]
ProgressBarDelegate = New ProgressBarDelegateHandler(AddressOf UpdateProgressBar)
t.Start()
End Sub
Private Sub oDll_ByteEnvoye(ByVal theDll As FasT_uPload_Lib.dll, ByVal theByte As Long) Handles oDll.ByteEnvoye
iByteDone += theByte
Dim lg As Long = (iByteDone / iLocalSize) * 100
' On est dans le thread de l'upload, donc on passe par un Invoke pour mettre à jour la progressbar
Me.Invoke(Me.ProgressBarDelegate, lg)
End Sub
Private Sub UpdateProgressBar(ByVal step As Long)
' Mise à jour de la barre de progression
' Cette fonction DOIT s'exécuter sur le thread de l'interface
pb.Value = step
Me.Refresh()
End Sub
Private Sub ThreadProcess()
' On fait l'upload dans le thread
oDll.UploadFile(LocalPath, DistantPath + Names.GetValue(Names.Length - 1))
' la mise à jour de la progress bar est faite dans l'évènement ByteEnvoye
End Sub
End Class |