WaitHandle.WaitAny blocks for multiple seconds despite timeout of 200ms

347 views Asked by At

In my program, I am facing some blocks for multiple seconds, which are leading to infrequent timeouts. I added some debug outputs and was now able to identify one responsible line of code:

Debug.WriteLine($"{DateTime.Now:HH:mm:ss.fff}: Before WaitAny");
int index = WaitHandle.WaitAny(mySyncEvents, 200, false);
Debug.WriteLine($"{DateTime.Now:HH:mm:ss.fff}: After WaitAny");

A small portion of the debug output shows:

02:42:29.636: Before WaitAny
02:42:29.841: After WaitAny
02:42:29.850: Before ExecuteScan
02:42:29.862: After ExecuteScan
02:42:29.863: Before WaitAny
02:42:43.520: After WaitAny       -> very long delay?
02:42:43.546: Before ExecuteScan

The question is now what could be the cause for this long delay of nearly 14 seconds despite the short timeout of 200ms? (In theory, also the first Debug.WriteLine may cause the delay, but I have not modified the Debug.Listeners collection.)

0

There are 0 answers