Waits until one or all of the specified objects are in the signaled state
#include <WinAPIProc.au3>
_WinAPI_WaitForMultipleObjects ( $iCount, $paHandles [, $bWaitAll = False [, $iTimeout = -1]] )
$iCount | The number of object handles in the array pointed to by $paHandles |
$paHandles | Pointer to an array of object handles |
$bWaitAll | [optional] If True, the function returns when the state of all objects in the $paHandles array is signaled. If False, the function returns when the state of any one of the objects is set to signaled. In the latter case, the return value indicates the object whose state caused the function to return. |
$iTimeout | [optional] 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 0, the function tests the states of the specified objects and returns immediately. If -1, the function's time-out interval never elapses. |
Success: | indicates the event that caused the function to return. |
Failure: | (-1) WAIT_FAILED, call _WinAPI_GetLastError() to get extended error information. |
Search WaitForMultipleObjects in MSDN Library.
#include <WinAPIHObj.au3>
#include <WinAPIProc.au3>
Global $g_tEvents = DllStructCreate("handle Event[3];")
$g_tEvents.Event(1) = _WinAPI_CreateEvent(0, True, False)
$g_tEvents.Event(2) = _WinAPI_CreateEvent(0, True, False)
$g_tEvents.Event(3) = _WinAPI_CreateEvent(0, True, False)
HotKeySet("{ESC}", "_Exit")
AdlibRegister("_FireEvent_1", 500)
AdlibRegister("_FireEvent_2", 800)
Local $iEvent
While 1
$iEvent = _WinAPI_WaitForMultipleObjects(3, $g_tEvents, False, 100)
Switch $iEvent
Case 0
ConsoleWrite("+ First Event" & @CRLF)
_WinAPI_ResetEvent($g_tEvents.Event(1))
Case 1
ConsoleWrite("> Second Event" & @CRLF)
_WinAPI_ResetEvent($g_tEvents.Event(2))
Case 2
ConsoleWrite("! Exit Event" & @CRLF)
AdlibUnRegister("_FireEvent_1")
AdlibUnRegister("_FireEvent_2")
_WinAPI_CloseHandle($g_tEvents.Event(1))
_WinAPI_CloseHandle($g_tEvents.Event(2))
_WinAPI_CloseHandle($g_tEvents.Event(3))
ExitLoop
Case -1 ;Error
ExitLoop
EndSwitch
Sleep(10)
WEnd
Func _Exit()
_WinAPI_SetEvent($g_tEvents.Event(3))
EndFunc ;==>_Exit
Func _FireEvent_1()
_WinAPI_SetEvent($g_tEvents.Event(1))
EndFunc ;==>_FireEvent_1
Func _FireEvent_2()
_WinAPI_SetEvent($g_tEvents.Event(2))
EndFunc ;==>_FireEvent_2