Hi,
"John Veldthuis" <wh******@you.s pam.me.com> wrote in message
news:gt******** *************** *********@4ax.c om...
On Tue, 27 Dec 2005 11:41:18 +1300, John Veldthuis
<wh******@you.s pam.me.com> wrote:
I have set up a background worker and now find I need to give it multiple
arguments.
What is the best way of doing this? An example would be nice.
Also forgot I need to return multiple results as well.
That doesn't change much, as per my previous reply you could use an array,
Hashtable or class to group parameters and pass them as an object (for
e.Argument and e.Result ):
* Example using an array (multiple args & results):
' start BackgroundWorke r
BackgroundWorke r1.RunWorkerAsy nc( New Object() { 10, "test" } )
' DoWork event
Private Sub BackgroundWorke r1_DoWork(ByVal sender As System.Object, ByVal e
As System.Componen tModel.DoWorkEv entArgs) Handles BackgroundWorke r1.DoWork
Dim args As Object() = DirectCast( e.Argument, Object() )
Dim arg1 As Integer = CInt(args(0))
Dim arg2 As String = CStr(args(1))
' do something
e.Result = New Object() { -1, "test" }
End Sub
Private Sub BackgroundWorke r1_RunWorkerCom pleted(ByVal sender As Object,
ByVal e As System.Componen tModel.RunWorke rCompletedEvent Args) Handles
BackgroundWorke r1.RunWorkerCom pleted
Dim ret As Object() = DirectCast( e.Result, Object() )
Dim ret1 As Integer = CInt(ret(0))
Dim ret2 As String = CStr(ret(1))
End Sub
HTH,
Greetings