CoWaitForMultipleHandles (ole32)
Last changed: anonymous

.
Summary

C# Signature:

[DllImport("ole32.dll")]
static extern int CoWaitForMultipleHandles(uint dwFlags, uint dwTimeout,
   uint cHandles, IntPtr [] pHandles, out uint lpdwindex);

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

This should be called as part of a long running process in Excel VSTO add-ins, for example.

Sample Code:

    System.Threading.ManualResetEvent event = new System.Threading.ManualResetEvent(false);
    System.IntPtr[] waitHandles = { event.SafeWaitHandle.DangerousGetHandle() };
    uint lpdwindex;
    while(/* Put condition here! */)
    {
        // Lots of work!!!

        CoWaitForMultipleHandles(0, 0, (uint)waitHandles.Length, waitHandles, out lpdwindex);
    }

Alternative Managed API:

Do you know one? Please contribute it!

Documentation