Reputation: 901
Sorry if this is a silly question, but can one create an array of Background Workers?
I am using the example from this post : how-to-use-wpf-background-worker
I'm doing document processing and would like to put each document in its own thread. Or should I use the same background worker object for each document?
Thx for any insight.
Upvotes: 0
Views: 480
Reputation: 69985
You could do that, but I feel that it is very unadvisable. Any time you need more than one BackgroundWorker
, you should start thinking about using other forms of threading.
For alternatives, please take a look at the Task
Class and Asynchronous Programming with Async and Await (C# and Visual Basic) pages at MSDN.
Upvotes: 3
Reputation: 4440
You can create a
List<BackgroundWorker> lstMyWorkers = new List<BackgroundWorker>();
list array no problem. BUT be aware. those thread are not necessary making things faster.
Too much threads running will end up being much more slower than inline code version on a single thread.
sweet spot is 6 to 10 simultaneous threads. 10 threads would be because you absolutely need that much at a time which is pretty rare. I use it at work on simulation software but other than those i haven't seen the use for more than 2-3 really.
I don't know good documentation or guideline webpage for do and don't but probably another fellow stacker might have a nice link for you.
Upvotes: 2