473,385 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

threads (background worker) question


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 this:

for (int i = 0; i < inputNum; i++)
{
string param = i.ToString();
bw.RunWorkerAsync(param);
}

So,how can I do it by running few threads with one background worker?

Thank you!
*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #1
7 2999
"csharpula csharp" <cs*******@yahoo.comwrote in message
news:ee**************@TK2MSFTNGP03.phx.gbl...
>
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 this:

for (int i = 0; i < inputNum; i++)
{
string param = i.ToString();
bw.RunWorkerAsync(param);
}

So,how can I do it by running few threads with one background worker?

Thank you!
*** Sent via Developersdex http://www.developersdex.com ***
This appears to be a perfect case for the ThreadPool, which is a pool of
background threads that you can use without declaring them. In addition, if
there are more tasks than there are threads, it will queue them until a
thread becomes available.

Mike.
Jun 27 '08 #2


But can't I use background worker for this purpose?

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #3

I mean how can I run few paralell threads using the background worker?
Thank u!
*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #4
csharpula csharp wrote:
I mean how can I run few paralell threads using the background worker?
Thank u!
*** Sent via Developersdex http://www.developersdex.com ***
You will need a background worker for all threads. That is, if you want
to run your task in 5 threads you need 5 backgroundworkers. In your
example you only have one but you'd need 5.

Alain
Jun 27 '08 #5
1 worker - 1 thread. You could spawn other threads inside the worker.
You may also want to look at the CCR in the robotics studio. It is not the
api that is so interesting, it is the non-blocking pattern using ports and
handlers.

"csharpula csharp" <cs*******@yahoo.comwrote in message
news:ee**************@TK2MSFTNGP03.phx.gbl...
>
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 this:

for (int i = 0; i < inputNum; i++)
{
string param = i.ToString();
bw.RunWorkerAsync(param);
}

So,how can I do it by running few threads with one background worker?

Thank you!
*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #6
Buth the question is if can I do something like that using the
background worker:

BackgroundWorker bw = new BackgroundWorker();
BackgroundWorker bw2 = new BackgroundWorker();

bw.RunWorkerAsync(2);
bw2.RunWorkerAsync(3);
and in this way create as much backgroundworkers as threads i need or
there is a better way doing it?
Thank u!
*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #7
Yes you can do that. Create as many as you need (and resource permits). I
thought you asked if you could do multiple threads with 1 BW.

"csharpula csharp" <cs*******@yahoo.comwrote in message
news:ew**************@TK2MSFTNGP04.phx.gbl...
Buth the question is if can I do something like that using the
background worker:

BackgroundWorker bw = new BackgroundWorker();
BackgroundWorker bw2 = new BackgroundWorker();

bw.RunWorkerAsync(2);
bw2.RunWorkerAsync(3);
and in this way create as much backgroundworkers as threads i need or
there is a better way doing it?
Thank u!
*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John | last post by:
If my main UI thread starts a worker thread, who starts its own worker thread. So if i just close my app, in the closing event i can kill the thread the UI thread starts. but how can i kill the...
2
by: Michael C | last post by:
Thank you all for all your help. My projects are chugging along now. I have one more quick question, if you don't mind. I'm calling the WTS API function WTSSessionEnumerate() multiple times on...
21
by: Doug Thews | last post by:
I was noticing that when I run a multi-threaded app from within the IDE and then I close the main form (which spun off all of the threads), that the Stop/Pause VCR buttons in the debugger are still...
9
by: Eric Sabine | last post by:
Can someone give me a practical example of why I would join threads? I am assuming that you would typically join a background thread with the UI thread and not a background to a background, but...
22
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
4
by: MSDousti | last post by:
Hi I have written a VB .NET app, which uses several threads. I thought that when the user closes the main window (when MainForm.closed event occures, and I call application.exit) all running...
4
by: gnassar | last post by:
Hello, I've written to this group a couple times and would like to initially start by thanking those who reply to the posts. I seem to be having some issues that are out of my understanding at...
1
by: chunghorng_lung | last post by:
Hi All, I have a question on the scope of variables for threads. The program has a main thread which creates a few worker threads. The main thread can access another class stored in another...
3
by: Peted | last post by:
Hi i hope i explaine this correctly I have a class with a method that reads and writes using blocking sockets to a TCP device. Call it class IPdevice. I can use this method to send commands and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.