The scenario I am facing is as below. Because ThreadPool is 1 instance per process so my question is that would method 1 cancel tasks queued by method 2 after 3 seconds?
http request comes in
*method 1 gets executed first*: ThreadPool.QueueUserWorkItem x 3 WaitHandle.WaitAll for 3 seconds *method 2 gets executed after method 1*: ThreadPool.QueueUserWorkItem x 10 WaitHandle.WaitAll for 10 seconds
Sorry I think I totally misunderstood the use of WaitHandle. It seems that if I do below everything will work as desired. So sorry for the confusion.
var calls = new ManualResetEvent[5];
//ThreadPool.QueueUserWorkItem blah...
WaitHandle.WaitAll(calls, timeOut);
But I am still thinking what will happen when method 1 flooded thread pool with long running tasks and method 2 only waits for 1 second. Will method 2 ever get its results back because it's not waiting long enough.
Thanks.