Desktop Functions:

   Smart Device Functions:

Show Recent Changes
Subscribe (RSS)
Misc. Pages
Helpful Tools
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
WaitForMultipleObjects (coredll)

coredll is for smart devices, not desktop Windows. Therefore, this information only applies to code using the .NET Compact Framework. To see if information for WaitForMultipleObjects in other DLLs exists, click on Find References to the right.

This function returns a value when either any one of the specified objects is in the signaled state, or the time-out interval elapses.

C# Signature:

[DllImport("coredll.dll", EntryPoint = "WaitForMultipleObjects", SetLastError = true)]
static extern int WaitForMultipleObjects(UInt32 nCount, IntPtr[] lpHandles, Boolean fWaitAll, UInt32 dwMilliseconds);

VB Signature:

Declare Function WaitForMultipleObjects Lib "coredll.dll" (ByVal nCount As Integer, ByVal lpHandles() As IntPtr, ByVal fWaitAll As Boolean, ByVal dwMilliseconds As Integer) As Integer

User-Defined Types:


Alternative Managed API:

Do you know one? Please contribute it!



nCount: Specifies the number of object handles in the array pointed to by lpHandles. The maximum number of object handles is MAXIMUM_WAIT_OBJECTS.

lpHandles: Pointer to an array of object handles. For a list of the object types whose handles can be specified, see the Remarks section. The array can contain handles of objects of different types.

fWaitAll: Specifies the wait type. This parameter must be set to FALSE. This causes function to return when the state of any one of the objects set to is signaled. The return value indicates the object whose state caused the function to return.

dwMilliseconds: Specifies the time-out interval in milliseconds. The function returns if the interval elapses, even if the conditions specified by the bWaitAll parameter are not met. If dwMilliseconds is zero, the function tests the states of the specified objects and returns immediately. If dwMilliseconds is INFINITE, the function's time-out interval never elapses.

Return Value:

If the function succeeds, the return value indicates the event that caused the function to return. The following table shows possible values.

WAIT_OBJECT_0 to (WAIT_OBJECT_0 + nCount –1): the return value minus WAIT_OBJECT_0 indicates the lpHandles array index of the object that satisfied the wait. If more than one object became signaled during the call, this is the array index of the signaled object with the smallest index value of all the signaled objects.

WAIT_TIMEOUT : the time-out interval elapsed and the condition specified by the fWaitAll parameter is not satisfied.

WAIT_FAILED indicates failure. To get extended error information, call GetLastError.

Tips & Tricks:

The Handle property of .NET EventWaitHandle objects are pseudo-handles, and cannot be used with this P/Invoke function. You can only use handles obtained from the CreateEvent P/Invoke function.

Sample Code:

IntPtr hNamedEvent1 = CreateEvent(IntPtr.Zero, false, false, "namedEvent1");
IntPtr hNamedEvent2 = CreateEvent(IntPtr.Zero, false, false, "namedEvent2");
IntPtr[] handles = new IntPtr[] { hNamedEvent1, hNamedEvent2 };

while (true)
    Int32 result = WaitForMultipleObjects((UInt32)handles.Length, handles, false, INFINITE);
    MessageBox.Show("Event " + result + " Occured");


Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

Access directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version