2010-05-11 67 views
2

我需要創建多個線程,當點擊一個按鈕,我已經做了這一點:如何知道線程中的工作何時完成?

Dim myThread As New Threading.Thread(AddressOf getFile) 
myThread.IsBackground = True 
myThread.Start() 

,但我需要更新與下載文件中的圖片框,購買,如果我在設置事件函數getFile並提高它以通知文件已下載,然後更新picturebox。

回答

7

使用AsyncResult,並定期檢查它是否完成,或者在線程完成其工作時提供一個委託以供調用。

VB can be found here中的完整示例。

1

您需要使用MethodInvoker解析。

Public Sub GetFile() 
    If Me.InvokeRequired Then 
     Me.Invoke(New MethodInvoker(GetFile)) 
    End If 
End Sub 

現在您可以處理指定類中的任何事件。

1

可以achive,使用Asyncallback,...

Dim sinctotal As New Del_sinc(AddressOf sincronizar) 

Dim ar As IAsyncResult = sinctotal.BeginInvoke(_funcion, type, New AsyncCallback(AddressOf SincEnd), cookieobj) 

的cookieobj是這個

Class Cookie 

    Public id As String 
    Public AsyncDelegate As [Delegate] 
    Sub New(ByVal id As String, ByVal asyncDelegate As [Delegate]) 

     Me.id = id 
     Me.AsyncDelegate = asyncDelegate 

    End Sub 


End Class 

當委託完成就會調用funcion Sincend(在這個例子中),然後你可以使用一個事件來更新你的照片。

希望這會有所幫助!

相關問題