WaitHandle.WaitAny匹配WaitForMultipleObjects的功能功能、WaitHandle、WaitAny、WaitForMultipleObjects

2023-09-04 10:09:38 作者:明若轻兮

我移植 C ++ API code到 .NET ,展望函数调用 WaitHandle.WaitAny 来替代 WaitForMultipleObjects的 .NET4 我可以看到,这个函数挂钩到

I am porting C++ API code to .NET and looking into function call WaitHandle.WaitAny as a replacement for WaitForMultipleObjects but when debugging with .NET4 i can see that this function is hooked into

private static extern int WaitMultiple(
                               WaitHandle[] waitableSafeHandle, 
                               int msTimeOut, 
                               bool exitContext, 
                               bool WaitAll);

这让我觉得,这个功能是不是sutable的端口。任何其他建议?

and this makes me think that this function is not sutable for the port. Any other suggestions?

推荐答案

这是事实, WaitHandle.WaitAny()不是很够,以匹配 WaitForMultipleObjects的()。但是,你只需要使用 WaitHandle.WaitAll的()

It is true that WaitHandle.WaitAny() is not quite enough to match the functionality of WaitForMultipleObjects(). But you just need to use WaitHandle.WaitAll() as well.

WaitHandle.WaitAny()匹配 WaitForMultipleObjects的()调用,使用为WaitAll 参数设置为 FALSE WaitHandle.WaitAll的()为WaitAll 匹配其设置为 TRUE WaitHandle.WaitAny() matches WaitForMultipleObjects() called with the WaitAll parameter set to FALSE,. WaitHandle.WaitAll() matches it with WaitAll set to TRUE.