More multi threading advice needed!

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

Hi,
Need more help with this.
I have an array of objects (Computer class).
The class has a method that takes a while to run and I want it to run in
it's own thread.

So I have code like this:

Private ProcessResultHandler As AsyncCallback = AddressOf ProcessResults


For i = 0 To ComputerArray.GetUpperBound(0)
sfh = AddressOf ComputerArray(i).UninstallAgent
sfh.BeginInvoke(ProcessResultHandler, Nothing)
Next i

Public Sub ProcessResults(ByVal ar as IAsyncResult)
sfh.EndInvoke(ar)

End Sub

Now, I need to know from within ProcessResults which object invoked it. The
Computer class has a Name property
that I need to get at. Is this possible with the above code?

Thanks!
Dan
 
Dan said:
Hi,
Need more help with this.
I have an array of objects (Computer class).
The class has a method that takes a while to run and I want it to run
in it's own thread.

So I have code like this:

Private ProcessResultHandler As AsyncCallback = AddressOf
ProcessResults


For i = 0 To ComputerArray.GetUpperBound(0)
sfh = AddressOf ComputerArray(i).UninstallAgent
sfh.BeginInvoke(ProcessResultHandler, Nothing)
Next i

Public Sub ProcessResults(ByVal ar as IAsyncResult)
sfh.EndInvoke(ar)

End Sub

Now, I need to know from within ProcessResults which object invoked
it. The Computer class has a Name property
that I need to get at. Is this possible with the above code?

Thanks!
Dan

There are a few solutions but a simple one is to change the BeginInvoke
call to

sfh.BeginInvoke(ProcessResultHandler, ComputerArray(i))

and then in ProcesResults add

Dim c As Computer = DirectCast(ar.AsyncState, Computer)

then c.Name, etc is available.
 
Back
Top