Threading Question - What happens if there are no threads in the thread pool?

I have the following code:

CancellationTokenSource cancelSource = new CancellationTokenSource();
_cancelTokenList.Add(cancelSource);

CancellationToken token = cancelSource.Token;

Task.Factory.StartNew(() =>
{
   StartTest(token);
}, token);

Will an exception be thrown if the threads are not available to service the request for a new task, or just wait until the thread becomes available? If he waits, how long will he wait?

+3
source share
3 answers

From MSDN:

You can queue as many thread pool requests as system memory allows. If there are more requests than thread pool threads, additional requests remain in the queue until thread pool threads become available.

- . , IsBackground . , ThreadPool .

, , .

+4

, . , , , . , , , .

+2

. TPL ( ) . , . , /threadpool ( 2/).

You are showing but not mentioning CancellationToken. It can only be used to request a cancellation , so I suspect that your StartTest () will be executed even if the token was canceled when the task was queued .

+2
source

All Articles