More multi threading advice needed!

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
 
M

Mark Hurd

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top