2010-05-11 72 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(在这个例子中),然后你可以使用一个事件来更新你的照片。

希望这会有所帮助!

相关问题