如何将值从BackgroundWorker
DoWork
to传递BackgroundWorker
Completed
?由于BackgroundWorker
Completed
不被调用,因此BackgroundWorker
DoWork
我不确定如何执行此操作,除非声明一个public variable
. 本质上,我想BackgroundWorker
Completed
通过ByVal
来自BackgroundWorker
DoWork
.
问问题
3298 次
1 回答
3
声明DoWork
函数时,请注意它内置了一些方便的参数:
Private Sub backgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs) _
Handles backgroundWorker1.DoWork
并注意RunWorkerCompleted
处理程序的类似参数:
Private Sub backgroundWorker1_RunWorkerCompleted(ByVal sender As Object, _
ByVal e As RunWorkerCompletedEventArgs) _
Handles backgroundWorker1.RunWorkerCompleted
至关重要的是,您可以访问e.Result
,它可以是任何对象,在RunWorkerCompletedEventArgs
,也可以e.Result
在您的DoWorkEventArgs
- 后者在方法完成时传递给前者,因此在您的工作方法结束时只需设置:
e.Result = myResult
然后在您的RunWorkerCompleted
处理程序中,您也可以通过以下方式访问它:
if e.Result = (whatever) then
.... etc
参考 :
于 2013-07-30T00:46:33.407 回答