I am porting C++ API
code to .NET
and looking into function call WaitHandle.WaitAny
as a replacement for WaitForMultipleObjects<
It is fine, it uses WaitForMultipleObjects() under the hood. Which you can find out with this little test program:
using System;
using System.Threading;
class Program {
static void Main(string[] args) {
var waits = new WaitHandle[65];
for (int ix = 0; ix < waits.Length; ++ix) waits[ix] = new ManualResetEvent(false);
WaitHandle.WaitAny(waits);
}
}
Same restriction that WaitForMultipleObjects has. The WaitMultiple() method is marked MethodImplOptions.InternalCall because it actually lives inside the CLR. Which wants to know about blocking waits in order to provide several managed threading guarantees. Like pumping a message loop on a UI thread to keep COM happy (MsgWaitForMultipleObjects), knowing when a remoting request can be suspended for the next request and knowing when a thread is in a safe state to honor abort requests.