VB.NET多线程使用例子
’定义Delegate
Private Delegate Function testDelegate(ByVal objParam As Object) As String
‘多线程调用
Public Function testIf(ByVal objParam As Object) As String
Dim testCall As New testDelegate(AddressOf test)
testCall.BeginInvoke(objParam, Nothing, Nothing)
Return ""
End Function
’实际需要调用的代码
Private Function test(ByVal objParamReport As Object) As String
‘do something
End Functio
以上就是代码片段。
以上是非阻塞式的多线程调用,也就是不会等待test执行完,直接执行后面的代码。
如果需要做成阻塞式调用,有两种方式。
※ 后面追加