threads (background worker) question

C

csharpula csharp

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!
 
W

William Stacey [C# MVP]

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.
 
C

csharpula csharp

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!
 
W

William Stacey [C# MVP]

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.
 

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

Top