Is it possible to group / isolate tasks in ThreadPool when using WaitHandle.WaitAll?

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];
//ThreadPool.QueueUserWorkItem blah...
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.

+2
4

, . . BTW, -, WaitAll ?

+1

, +, . - . , ( Guard), "" "" . article, , .

!

+1

, method 1 , method 2, method 1, method 2 .

, , method 2 method 1 , method 1, .

, , , , , , , .

+1

:

, WaitAll , [MTAThread] ( ).

ThreadPool ( ), , .

+1
source

All Articles