The documentation for WaitHandle.WaitAny Method (WaitHandle[], Int32) says it returns "The array index of the object that satisfied the wait, or WaitTimeout if no object satisfied the wait and a time interval equivalent to millisecondsTimeout has passed" and in the Assembly Browser I see that WaitHandle.WaitTimeout is 258.
So why do I sometimes get 0x7fffffff (Int32.MaxValue) as a return value from this function?
Is this a known bug in WaitAny(), or just a line missing from the documentation?
ADDED LATER:
By the way, the error happens a couple of times, then goes away, without me doing anything to "fix" the handles or anything like that.
Code:
class CommandQueue
{
EventWaitHandle m_abortRequest = new EventWaitHandle (false, EventResetMode.AutoReset);
Semaphore m_commandCount = new Semaphore (0, 10000);
public CommandQueue ()
{
m_processTask = new Task(() => Process ());
m_processTask.Start ();
}
public async Task Process()
{
WaitHandle [] handles = new WaitHandle [2];
handles [0] = m_abortRequest;
handles [1] = m_commandCount;
for (;;)
{
int wait = WaitHandle.WaitAny (handles, 500);
if (wait == WaitHandle.WaitTimeout)
{
OnIdleTimer ();
}
else if (wait == 0)
{
// SNIP: Code to handle a request to abort the processing of commands
break;
}
else if (wait == 1)
{
// SNIP: Code to process the next command in the queue
await Process(nextCommand);
}
else
{
Debug.WriteLine ("*** Unexpected WaitAny(" + wait + " = 0x" + wait.ToString("X6") + ")!");
}
}
}
}