该BackgroundWorker
组件有一个IsBusy
标志。在执行时RunWorkerASync
,此标志设置为 True。RunWorkerASync
完成时或完成时它会更改为 FalseRunWorkerCompleted
吗?
问问题
394 次
1 回答
-1
该标志将在结束后IsBusy
立即设置为 false ,然后再执行。假设您想从另一个函数中检索 ' 操作的结果,如下所示:RunWorkerASync
RunWorkerCompleted
BackgroundWorker
Dim MyResult = "Not Set"
Sub Foo()
DoSomeStuff()
RunWorkerASync()
'Wait for worker
While Worker.IsBusy
Wait()
End While
'Use result
'This won't work because MyResult hasn't been
'set yet by the RunWorkerCompleted handler
'Will Print "Not Set", unless, by a timing quirk,
'RunWorkerCompleted has enough time to execute
'Before using its result.
Print MyResult
End Sub
Sub RunWorkerASync()
e.Result = "Result has been set"
End Sub
Sub RunWorkerCompleted()
MyResult = e.Result 'Worker's output
End Sub
于 2012-12-07T21:21:09.657 回答