我听说在多个线程上使用 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# - 等待全部限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4191014/