c# - 等待全部限制

标签 c# .net

我听说在多个线程上使用 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/

相关文章:

c# - ASP.NET mvc4 DropDownListFor 传回一个对象

c# - 如果我在 Observable 的订阅回调中抛出异常会发生什么?

c# - Entity Framework - 如何从联结表中删除数据

c# - 如何在单击按钮时调用方法?

c# - 验证构造函数参数

c# - WinForms 报表查看器 : mouse wheel scrolls two pages instead of one

.net - 是否有 Groovy 和 Grails 或 Ruby on Rails 的 .NET 等价物?

c# - .NET Core 2.1 API Post Controller 返回无效输入

c# - 在C#中将基类转换为子类

c# - 异步方法在 ASP.NET (MVC) 中的何处执行?