What about using the Tasks to do your threading for you.
What about using the Tasks to do your threading for you. msdn.microsoft.com/en-us/library/system.... var task1 = Task.Factory. StartNew(() => DoSomeWork()); var task2 = Task.Factory.
StartNew(() => DoSomeWork()); var task3 = Task.Factory. StartNew(() => DoSomeWork()); Task. WaitAll(task1, task2, task3).
1 It's . NET Framework 4. So I have to upgrade the project.It's seems to be a better approach thought!
– Amir Rezaei Nov 16 '10 at 12:27.
Actually I use the following to replace WaitHandle. WaitAll(doneEvents); foreach (var e in doneEvents) e.WaitOne().
Use one ManualResetEvent and wait on it. Also maintain a TaskCount variable that is set to the number of worker threads you start, use Interlocked. Decrement in the worker thread code as the very last action of the worker and signal the event if the counter reaches zero,e.g. // other worker actions... if (Interlocked.
Decrement(ref taskCount) == 0) doneEvent.Set().
Thanks it seems to be the only solution since WaitAll(..) doesn’t work. – Amir Rezaei Nov 16 '10 at 12:15 Yep, that would work. Just make sure to treat the main thread as if it were a work item and initialize taskCount = 1 and do the Decrement and Set at the end of the for loop.
– Brian Gideon Nov 16 '10 at 14:05.
I would refactor your code to use the CountdownEvent class instead. Private void Search() { const int CPUs = 2; var done = new CountdownEvent(1); // Configure and launch threads using ThreadPool: for (int I = 0; I { try { f. WaitCallBack(state); } finally { done.Signal(); } }, i); } // Wait for all threads in pool done.Signal(); done.Wait(); Debug.
WriteLine("Search completed! "); }.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.