I am having tasks which are running Work method
private void Work(Crawler crawler, PropertyBag propertyBag) {}
Now I want to stop all taks for 3 minutes and then continue with execution. I try with
Thread.Sleep but not working. Tasks still working. What is good solution to stop tasks for 3 minutes and then continue. Maybe locking and how to do it?
Thread.Sleepdoes not work because it sleeps the current thread.If you create the threads by hand, not using TPL, then you hopefully have a list/array of the threads. You can use the Thread.Suspend and Thread.Resume methods.
Note that Sleep/Resume are obsolete!
EDIT
Without having a list of threads, then you can use a
ManualResetEvent. In your Work method do a.WaitOne()on it before attempting to any work.On your main thread call
.Resetwhen you want to sleep the tasks, and then in 3 minutes call.Set.