vb.net检查过程结束,并修改UI
我有一个问题,我的程序(启动进程时)最小化到系统托盘中,进程结束时,它以正常状态显示,但它与我的解决方案不兼容,我收到以下错误消息: System.Windows.Forms.dll中发生类型为“System.InvalidOperationException”的未处理异常 我的代码:vb.net检查过程结束,并修改UI,vb.net,forms,process,main,Vb.net,Forms,Process,Main,我有一个问题,我的程序(启动进程时)最小化到系统托盘中,进程结束时,它以正常状态显示,但它与我的解决方案不兼容,我收到以下错误消息: System.Windows.Forms.dll中发生类型为“System.InvalidOperationException”的未处理异常 我的代码: Dim p as new Process p.filename = "somefile.exe" p.workingdirectory = "somepath" p.EnableRaisingEvents = T
Dim p as new Process
p.filename = "somefile.exe"
p.workingdirectory = "somepath"
p.EnableRaisingEvents = True
AddHandler p.Exited, AddressOf Main.Main_Process_Closed
p.Start()
主窗体中的处理程序:
Public Sub Main_Process_Closed(ByVal sender As Object, ByVal e As System.EventArgs)
Me.Visible = True
Me.WindowState = FormWindowState.Normal
NotifyIcon1.Visible = False
End Sub
但问题是什么?感谢您的帮助。当您添加处理程序时,该处理程序可能会被UI线程以外的辅助线程调用。因此,您无法直接操作UI线程 您需要使用Invoke来正确封送到UI线程。这里有一个很好的例子,可以帮助你度过难关