The scenario I came across is as follows. Since ThreadPool is 1 instance per process, so my question is, will method 1 cancel the 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 didn’t fully understand the use of WaitHandle. It seems that if I do below, everything will work as she wants. Sorry for the confusion.
var calls = new ManualResetEvent[5];
WaitHandle.WaitAll(calls, timeOut);
But I still think what will happen when method 1 starts the thread pool with long jobs and method 2 only waits 1 second. Will method 2 get the results because it does not wait long enough.
Thanks.