密码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
Dim Process1 As New Process
Process1.StartInfo.FileName = ("data\test.exe")
Process1.EnableRaisingEvents = True
AddHandler Process1.Exited, AddressOf OnExit
Process1.Start()
End Sub
Sub OnExit(ByVal sender As Object, ByVal e As EventArgs)
Button1.Enabled = True
End Sub
我试着...
Sub OnExit(ByVal sender As Object, ByVal e As EventArgs)
Procces1.Close()
Button1.Enabled = True
End Sub
仍然错误
有什么解决办法吗?
1条答案
按热度按时间iih3973s1#
由于OnExit是由另一个线程调用的,因此必须使用Control.BeginInvoke Method来修改
Button1
属性。您可以从this question (Crossthread operation not valid)使用此Sub来控制Enabled状态:
更新代码: