此循环非常占用CPU: While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE GUIDelete() Exit Case $control1 Func1() Case $control2 Func2() EndSwitchWEnd 这就是我一直用的东西.我知道还有其他方法,但哪一个是
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
GUIDelete()
Exit
Case $control1
Func1()
Case $control2
Func2()
EndSwitch
WEnd
这就是我一直用的东西.我知道还有其他方法,但哪一个是CPU密集度最低的?
我也使用 Switch/Case遇到了这个问题.我认为使代码更紧凑,更改为 Select/Case会降低CPU使用率.我最终做的是在 a Do/Until loop陷阱.此摘录来自一个脚本,该脚本位于任务栏中并始终运行.用户通过单击并从我创建的上下文菜单中进行选择进行交互这开启了各自的功能.
While 1
Do
$msg = TrayGetMsg()
Until $msg <> 0
Select
Case $msg = $ItemDeviceModel
DeviceModel()
Case $msg = $ItemSerial
SerialNumber()
Case $msg = $ExitItem
Exit
EndSelect
WEnd
在此示例中,脚本循环快速简单的Do / Until(等待用户单击应用程序图标).循环中断后,Select / Case运行.
切换代码:
While 1
Do
$msg = GUIGetMsg()
Until $msg <> 0
Switch $msg
Case $GUI_EVENT_CLOSE
GUIDelete()
Exit
Case $control1
Func1()
Case $control2
Func2()
EndSwitch
WEnd
