gpt4 book ai didi

c# - 线程问题 - 如果线程池中没有可用线程会怎样?

转载 作者:行者123 更新时间:2023-11-30 14:02:20 27 4
gpt4 key购买 nike

我有以下代码:

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

CancellationToken token = cancelSource.Token;

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

如果没有可用的线程来为新任务的请求提供服务,是否会抛出异常,还是会一直等到有线程可用时才抛出异常?如果等待,它会等多久?

最佳答案

来自 MSDN:

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

The threads in the managed thread pool are background threads. That is, their IsBackground properties are true. This means that a ThreadPool thread will not keep an application running after all foreground threads have exited.

它将一直等到一个可用,或者您的应用程序退出。

关于c# - 线程问题 - 如果线程池中没有可用线程会怎样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6124808/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com