创建或打开有名或无名的信号量对象.
#Include <WinAPIEx.au3>
_WinAPI_CreateSemaphore ( $sSemaphore, $iInitial, $iMaximum [, $tSecurity] )
$sSemaphore | 信号量的名称. 名称比较区分大小写. |
$iInitial | 信号量对象的初始计数. 该值必须大于或等于 0, 且小于或等于 $iMaximum |
$iMaximum | 信号量对象的最大数量. 该值必须大于 0. |
$tSecurity | [可选参数] $tagSECURITY_ATTRIBUTES structure that specifies a security descriptor for the new semaphore. If this parameter is 0, the semaphore gets a default security descriptor. |
成功: | 返回信号量对象的句柄.如命名信号量对象在函数调用前已存在,函数返回现有对象的句柄. |
失败: | 返回 0,并设置@error标志为非 0 值. |
在MSDN中搜索
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
If Not @Compiled Then
MsgBox(0, '', 'To run this script, you must first compile it and then run the (.exe) file.')
Exit
EndIf
Global $hSemaphore = _WinAPI_CreateSemaphore('MySemaphore', 2, 2)
_WinAPI_WaitForSingleObject($hSemaphore)
_MyGUI()
_WinAPI_ReleaseSemaphore($hSemaphore)
_WinAPI_CloseHandle($hSemaphore)
Func _MyGUI()
Local $Msg
GUICreate('MyGUI')
GUISetState()
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case -3
ExitLoop
EndSwitch
WEnd
EndFunc ;==>_MyGUI