|
本人想编写个服务器检测程序,检测主机可从配置文件中读取,所以个数是动态的,想用多线程,对检测的每台主机单独使用线程,要不然只要有一台机子ping值高,就会影响全局,但线程数量又是不固定的,要跟据主机的多少来定,如何实现,以下是多线程代码,关键就卡在最后的那个函数上,请高手指教!!!多谢!!!
$Form1 = GUICreate("多线程实例", 272, 139, -1, -1)
$Label1 = GUICtrlCreateLabel("00:00:00:00", 8, 8, 146, 17)
$Label2 = GUICtrlCreateLabel("0", 8, 56, 150, 17)
$Label3 = GUICtrlCreateLabel("", 8, 104, 148, 17)
$Button1 = GUICtrlCreateButton("关闭线程1", 168, 8, 89, 25, 0)
$Button2 = GUICtrlCreateButton("关闭线程2", 168, 48, 89, 25, 0)
$Button3 = GUICtrlCreateButton("关闭线程3", 168, 96, 89, 25, 0)
GUISetState(@SW_SHOW)
Global $t2, $t3 = 1
Dim $Timer[3],$TimerDLL[3][2]
For $I = 0 To 2
$Timer[$I] = DllCallbackRegister("Timer", "int", "hwnd;uint;uint;dword")
$TimerDLL[$I][1] = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 1000, "ptr", DllCallbackGetPtr($Timer[$I]))
Next
While 1
Switch GUIGetMsg()
Case - 3
Exit
Case $Button1
DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $TimerDLL[0])
DllCallbackFree($Timer[0])
Case $Button2
DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $TimerDLL[1])
DllCallbackFree($Timer[1])
Case $Button3
DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $TimerDLL[2])
DllCallbackFree($Timer[2])
EndSwitch
WEnd
Func Timer($hWnd, $uiMsg, $idEvent, $dwTime)
MsgBox(4096, "Timer", "$TimerDLL[0]:"&$TimerDLL[0][0], 10)
If $idEvent = $TimerDLL[0][0] Then
GUICtrlSetData($Label1, @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC)
ElseIf $idEvent = $TimerDLL[1][0] Then
$t2 += 1
GUICtrlSetData($Label2, $t2)
ElseIf $idEvent = $TimerDLL[2][0] Then
$t3 *= 2
GUICtrlSetData($Label3, $t3)
EndIf
EndFunc |
|