gpt4 book ai didi

c# - WaitAll 限制

转载 作者:行者123 更新时间:2023-11-30 22:42:52 25 4
gpt4 key购买 nike

我听说在多个线程上使用 waitall 时存在限制(要等待的线程数?)。谁能给详细点?

最佳答案

我认为你所指的限制不是线程的数量;它取决于正在等待的句柄 的数量。来自MSDN page对于 WaitHandle.WaitAll(WaitHandle[]):

On some implementations, if more than 64 handles are passed, a NotSupportedException is thrown.

在极少数情况下会出现此问题,我通常使用以下方法解决它:

WaitHandle[] handles = ...

foreach(var waitHandle in handles)
waitHandle.WaitOne();

为了完整起见,其他限制似乎是:

If the array contains duplicates, the call fails with a DuplicateWaitObjectException.

The WaitAll method is not supported on threads that have STAThreadAttribute.

关于c# - WaitAll 限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4191014/

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