QueueCompareProcessThread()消息中的异常:值不属于预期范围。跟踪:在System.Threading.WaitHandle.WaitMultiple(WaitHandle[] waitHandles,Int32 millisecondsTimeout,Boolean,Boolean ) at System.Threading.WaitHandle.WaitAny(WaitHandle[] waitHandles,Int32 millisecondsTimeout,Boolean )在System.Threading.WaitHandle.WaitAny(WaitHandle[] waitHandles)
当我在线程中的一个WaitAny上使用WaitHandle方法时,我得到了上面的异常。请帮我解决这个问题。下面是我的部分代码:
public void QueueCompareProcessThread(QueueProcesses Qp)
{
try
{
WaitHandle[] pHandles = Qp.GetRunningProcessesHandles();
WaitHandle.WaitAny(pHandles);
Qp.RemoveExitedProcess(); // clearing the process list
// strange behavior is while clearing the process list i'm getting the exception in the thread Waitany method
// Does Waitany method still working after it returns?
}
catch (Exception e)
{
utils.Log("QProc Exception at QueueCompareProcessThread() Message:" + e.Message + " Trace:" + e.StackTrace);
}
}有人能给我一些关于WaitAny方法的想法并帮助我解决这个问题吗?
发布于 2016-07-26 09:41:07
您需要确保pHandles数组实际包含元素,并且每个元素只包含一次。文档声明,如果“__waitHandles是一个没有元素的数组,并且.NET框架版本为2.0或更高版本”,则抛出ArgumentException。
if (pHandles.Any())
{
WaitHandle.WaitAny(pHandles);
}https://stackoverflow.com/questions/38586111
复制相似问题