473,486 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Getting a reference to the actual background worker

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
3 1369
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

303
17411
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
7
10036
by: John J. Hughes II | last post by:
I have a DataGridView with a TextBoxColumn. I setting the data source to a List<stringvalue in a static class. The list is filled from a background thread. So far all is fine and it works...
6
5947
by: sjoshi | last post by:
I'm able to use the Bacground Worker class to execute task and pain the UI. However I want to be able to execute n tasks in order, say n1, then n2 if there were no errors during n1, n3 so on. ...
8
5334
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In...
4
4302
by: Jesse Aufiero | last post by:
I'm wondering what the rule is on how to assure that the background worker 'DoWork' routine is truly running entirely in the background. My DoWork routine calls another procedure which resides in...
4
2401
by: csharpula csharp | last post by:
Hello, Can you please tell me if I should use the background worker in the following way: if (worker.IsBusy) worker.CancelAsync(); (or I can avoid this if)? And in case I want to restart the...
7
3005
by: csharpula csharp | last post by:
Hello, I got a question regarding the usage of background worker. How can I run few threads via background worker with different objects as parameter each time. I understood that I can't do...
275
12024
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
1
2010
by: Infog | last post by:
I am trying to code a simple background workers class without needing to use the backgroundworker object on a form. This would allow me to use a background worker in any class without writing much...
0
7100
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5434
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.