BackgroundWorker and multiple Threads

R

Roger Crawfis

I am using the new BackgroundWorker for an I/O intensive application and it
works great!!!

I have a few questions though that hopefully someone can answer. I know this
is possible with other components, but am curious as to what
BackgroundWorker can do.

1) All the documentation indicates a single DoWork. Can I assign multiple
delegates to the DoWork event? It seems like I ought to be able to since it
is a general event.
2) If I do, will it spawn a thread for each delegate? The events can fire
sequentially.
3) Do I need a RunWorkerCompleted delegate for each DoWork delegate? Here is
where the simple utility afforded by BackgroundWorker starts to break down.

I am reading and converting hundreds of files and what I want to do is have
3-5 threads working on this (with the ability for the user to cancel all of
the work). I know this is possible using general threading, but can
BackgroundWorker accomplish this?

Roger
 
R

Roger Crawfis

One additional question:
4) Can I have multiple BackgroundWorker Components in a single form. This
seems like the easiest solution.

Roger
 
K

Kevin Spencer

Hi Roger,

Yes, you can use multiple BackgroundWorker components in a Form. This would
be a better solution than using multiple DoWork delegates, as they would all
run in the same thread as the BackgroundWorker (in sequence, one after the
other).

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Development Numbskull

Nyuck nyuck nyuck
 

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