From: Dan on
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


--

HTH
Dan Artuso



From: Mark Hurd on
"Dan" <dartuso(a)NOSPAMpagepearls.com> wrote in message
news:O8g0L8rvKHA.5936(a)TK2MSFTNGP04.phx.gbl...
> 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.

--
Regards,
Mark Hurd, B.Sc.(Ma.) (Hons.)