By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,933 Members | 1,563 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,933 IT Pros & Developers. It's quick & easy.

Getting a reference to the actual background worker

P: n/a
I define a Background Worker as follows:

Dim MyWorker(10) As System.ComponentModel.BackgroundWorker

For n=1 to 10
MyWorker(n)= New System.ComponentModel.BackgroundWorker
AddHandler MyWorker (n).DoWork, AddressOf MyWorker_DoWork
AddHandler MyWorker (n).RunWorkerCompleted, AddressOf MyWorker_AllDone
Next

I launch the worker as follows with a parameter 'n'

If Myworker(n).IsBusy = False Then
MyWorker(n).RunWorkerAsync(n)
End If

When the thread ends, I want to get a reference to the actual thread that
has ended. This will be the parameter 'n'. I can get a reference to the
thread itself but I can't see a way of getting to 'n'
Sub MyWorker_AllDone(ByVal sender As Object, ByVal e As
System.ComponentModel.RunWorkerCompletedEventArgs)
Dim c As System.ComponentModel.BackgroundWorker =
DirectCast(sender, System.ComponentModel.BackgroundWorker)
'What can I put here?

End Sub

-Jerry
Feb 8 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Jerry Spence1" <je**********@somewhere.co.ukschrieb
Sub MyWorker_AllDone(ByVal sender As Object, ByVal e As
System.ComponentModel.RunWorkerCompletedEventArgs)
Dim c As System.ComponentModel.BackgroundWorker =
DirectCast(sender, System.ComponentModel.BackgroundWorker)
'What can I put here?

End Sub

Index = Array.IndexOf(MyWorker, sender)
Armin
Feb 8 '08 #2

P: n/a
Jerry Spence1 wrote:
Dim MyWorker(10) As System.ComponentModel.BackgroundWorker
For n=1 to 10
MyWorker(n)= New System.ComponentModel.BackgroundWorker
AddHandler MyWorker (n).DoWork, AddressOf MyWorker_DoWork
AddHandler MyWorker (n).RunWorkerCompleted, AddressOf MyWorker_AllDone
Next

I launch the worker as follows with a parameter 'n'

If Myworker(n).IsBusy = False Then
MyWorker(n).RunWorkerAsync(n)
End If

When the thread ends, I want to get a reference to the actual thread that
has ended. This will be the parameter 'n'. I can get a reference to the
thread itself but I can't see a way of getting to 'n'
I've not used the BackgroundWorker yet, but if it's anything like the
other asynchronous methods, your 'n' should be taken as "state" data
which, /if/ I read MSDN right, you should be able to get hold of through
e.UserState.

HTH,
Phill W.
Feb 8 '08 #3

P: n/a
That's brilliant!

Thanks Armin

-Jerry
"Armin Zingler" <az*******@freenet.dewrote in message
news:up**************@TK2MSFTNGP06.phx.gbl...
"Jerry Spence1" <je**********@somewhere.co.ukschrieb
>Sub MyWorker_AllDone(ByVal sender As Object, ByVal e As
System.ComponentModel.RunWorkerCompletedEventArgs )
Dim c As System.ComponentModel.BackgroundWorker =
DirectCast(sender, System.ComponentModel.BackgroundWorker)
'What can I put here?

End Sub

Index = Array.IndexOf(MyWorker, sender)
Armin

Feb 11 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.