这是我的循环代码:
Do While potsStatus = True
Dim ForeGroundHwnd As IntPtr = GetForegroundWindow
Dim MySearchWinow As IntPtr = FindWindow(Nothing, SearchWindow)
If ForeGroundHwnd = MySearchWinow Then
If rbQ.Checked = True Then
keybd_event(vbKeyQ, 0, 0, 0)
keybd_event(vbKeyQ, 0, KEYEVENTF_KEYUP, 0)
Thread.Sleep(1)
ElseIf rbW.Checked = True Then
keybd_event(vbKeyW, 0, 0, 0)
keybd_event(vbKeyW, 0, KEYEVENTF_KEYUP, 0)
Thread.Sleep(1)
ElseIf rbE.Checked = True Then
keybd_event(vbKeyE, 0, 0, 0)
keybd_event(vbKeyE, 0, KEYEVENTF_KEYUP, 0)
Thread.Sleep(1)
ElseIf rbR.Checked = True Then
keybd_event(vbKeyR, 0, 0, 0)
keybd_event(vbKeyR, 0, KEYEVENTF_KEYUP, 0)
Thread.Sleep(1)
End If
End If
问题是当循环正在运行并且我退出/关闭它遇到错误的应用程序时,进程仍然存在并且循环永远不会结束。我唯一能做的就是在任务管理器中手动停止该进程。我希望有人可以帮助我。
编辑:解决。我在表单关闭事件中使循环为假。谢谢。