You are disposing the WaitHandle immediately after queueing the work items. There is race between the call to Dispose in the main thread and Set in the worker thread. There may be other problems, but it is difficult to guess because the code is incomplete.
You are disposing the WaitHandle immediately after queueing the work items. There is race between the call to Dispose in the main thread and Set in the worker thread. There may be other problems, but it is difficult to guess because the code is incomplete.
Here is how the pattern is suppose to work. Using (var finished = new CountdownEvent(1)) { foreach (var item in reportingDataList) { var captured = item; finished.AddCount(); ThreadPool. QueueUserWorkItem( (state) => { try { DoSomeWork(captured); // FillReportingData?
} finally { finished.Signal(); } }, null); } finished.Signal(); finished.Wait(); } The code uses the CountdownEvent class. It is available in . NET 4.0 or as part of the Reactive Extensions download.
1 The disposing of the AutoResetEvent was the first red flag I seen, however, without the full code it is difficult to pinpoint it exactly, but I would be adamant that this is part of the overall problem. – James Sep 15 '10 at 18:06.
As Hans pointed out, it is not clear where "i" is coming from. But also I can see your disposing block going out and disposed because you are not using WaitOne on it (or you have not copied that part of code). Also I would prefer to use WaitAll and not using interlocked.
WaitAll in this particular scenario would be fine, however, it does have it's limitations at higher volumes. – James Sep 15 '10 at 17:46.
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.