提问人:Uriel Katz 提问时间:7/30/2013 更新时间:7/30/2013 访问量:3562
将值从 BackgroundWorker DoWork 传递到 BackgroundWorker Completed
Pass values from BackgroundWorker DoWork to BackgroundWorker Completed
问:
如何将值从 传递到 ?由于不是由调用的,除了声明一个 .从本质上讲,我想通过一个变量接受 .BackgroundWorker
DoWork
BackgroundWorker
Completed
BackgroundWorker
Completed
BackgroundWorker
DoWork
public variable
BackgroundWorker
Completed
ByVal
BackgroundWorker
DoWork
答:
3赞
J...
7/30/2013
#1
当你声明你的函数时,请注意它内置了一些方便的参数: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
参考:
评论