Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hii,
How to run multiple background worker in a single form go so that all the worker works in same speed...

my prome ...?
i have 5 backgroundworker in one form and trying to run them in one speed (all of them) .
but what m facing is when i run all the background worker using button click event they run one after another with a diffrence of 3 to 4 sec ...
_______________________________

I want all of them to run at one go and in one speed ....

need help

thnxxs in advance
Posted
Comments
Sascha Lefèvre 9-May-15 9:47am    
Maybe we can help you better if you tell us why you want to run them "at the same speed".

1 solution

You can't make the threads run at the same speed as Windows is not a real-time operating system.

The best you can do is to synchronize the start of all of the BackgroundWorkers by setting up a ManualResetEvent. The code at the start of each Worker gets to the MRE and waits for the signal to start. Once you start all of your BGW's, then next statement should be setting the signal on the MRE, releasing the BGW's to do the rest of their work.

Even then, you're not going to get a perfect start. You're sharing the CPU cores with all of the other threads running in Windows! Some or all of your threads may not be running at all until Windows gets around to it. There is nothing you can do about this.
 
Share this answer
 
Comments
Rohit Malhotra 11-May-15 7:31am    
hii dev can you plzzz give me a code to run 5 BGW with MRE (manualresetevent)....
Dave Kreskowiak 11-May-15 7:48am    
Nope. I've got my own project I have to work on.

Google for "C# ManualResetEvent" for examples on how to use it.
Member 10521418 11-May-15 7:54am    
hmmmmm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900