我一直在尝试让一个函数与 GUI 窗口异步工作,但成功非常有限。
下面的代码是我的函数 XXX,带有一个委托和回调 - 允许停止 GUI 线程,而不会出现错误。
但它可以工作——如果它是一个 Sub,而不是一个函数,并且它没有任何参数。
我不知道如何更改它,以便检查它的返回值...我在一些示例中找到了一些帮助, http: //msdn.microsoft.com/en-us/library/system.iasyncresult.asyncstate .aspx - 但他们在回调中打印返回值,我看不到如何在调用者中获取它。
我找不到在我的函数中使用参数的任何方法。
Private Function XXX_Callback(ByVal ia As IAsyncResult)
Dim d As XXXDelegate = CType(CType(ia, Runtime.Remoting.Messaging.AsyncResult).AsyncDelegate, XXXDelegate)
d.EndInvoke(ia)
Dim result As AsyncResult = CType(ia, AsyncResult)
Dim caller As XXXDelegate = CType(result.AsyncDelegate, XXXDelegate)
Dim returnValue As Boolean = caller.EndInvoke(ia)
XXX_Finish() ' needs the "vvv argument, I don't know how to get it
' The returnValue is here but I don't know how to send it to the caller
End Function
'Private Function XXX_Finish(ByVal vvv as Boolean) As Boolean
' this probably needs to return something, I don't know what/ how to get it
Private Function XXX_Finish() As Boolean
' something
myGui.Finish()
End Function
' Private Delegate Function XXXDelegate(ByVal vvv As Integer) As Boolean
' Public Function XXX(ByVal vvv As Integer) As Boolean ' This is what I would like
Private Delegate Sub XXXDelegate()
Public Sub XXX()
'
myGui.Update()
'
End Sub
Public Sub Caller()
'
myGui = New SomeGui()
myGui.Begin()
Dim t As New XXXDelegate(AddressOf XXX)
t.BeginInvoke(AddressOf XXX_Callback, Nothing)
' more code, another call
End Sub
Private myGui As SomeGui
拜托,有人可以帮我把它变成一个更好的形状,或者得到一些有帮助的例子吗?用这两天找的那些,我已经走到了死胡同……
谢谢你。