VBNet BackGroundWorker在RunWorkerCompleted Event中传递参数

时间:2012-01-15 08:59:19

标签: .net vb.net backgroundworker

我可以看到的当前解决方案是通过在类中使用共享变量来传递值。

我的应用程序的表单加载我叫:workerSample.RunWorkerAsync

Dim finalList As List(Of String)
Private Sub workerSample_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles workerSample.DoWork
    Dim xList As New List(Of String)
    'long process of finding folder which contains executable files
    finalList = xList
End Sub

Private Sub workerSample_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles workerSample.RunWorkerCompleted
    'do something with finalList
End Sub

是否有另一种方法可以通过使用参数将xList变量传递给RunWorkerCompleted

1 个答案:

答案 0 :(得分:2)

Dim finalList As List(Of String)

Private Sub workerSample_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles workerSample.DoWork
    Dim xList As New List(Of String)
    e.Result = xList
End Sub

Private Sub workerSample_RunWorkerCompleted(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles workerSample.RunWorkerCompleted
    Me.finalList = e.Result
End Sub