Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
vb.net检查我启动的进程是否完成_Vb.net - Fatal编程技术网

vb.net检查我启动的进程是否完成

vb.net检查我启动的进程是否完成,vb.net,Vb.net,我已经开始了一个过程: Dim getUdpate as Process getUpdate = New Process getUpdate.StartInfo.FileName = "C:\UTIL\GETBTCH.BAT" getUpdate.StartInfo.WindowStyle = ProcessWindowStyle.Hidden getUpdate.StartInfo.UseShellExecute = False getUpdate.StartInfo.WorkingDirec

我已经开始了一个过程:

Dim getUdpate as Process
getUpdate = New Process
getUpdate.StartInfo.FileName = "C:\UTIL\GETBTCH.BAT"
getUpdate.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
getUpdate.StartInfo.UseShellExecute = False
getUpdate.StartInfo.WorkingDirectory = "C:\UTIL\"
getUpdate.Start()
getUpdate.Close()
然后,我想运行另一个进程,但我想首先检查
getUpdate
进程是否已经完成

如何检查流程是否已完成

我已经尝试查看进程ID,但它只显示cmd.exe,并且有很多cmd.exe作为进程ID,因此我不能只是去停止所有这些操作。

尝试:

getUpdate.WaitForExit()而不是

getUpdate.Close()
您可以检查进程的属性。如果进程已结束,则返回true;如果进程仍在运行,则返回false


在调用
getUpdate
Process对象上的
Close()
之前,需要检查此项。因此,在进程退出之前,
getProcess
必须保持打开状态。

如果您正在创建WinForms应用程序或类似的交互式UI,我建议将函数挂接到对象的事件中,而不是轮询
haseExited

(您可能已经知道这一点,但是)如果使用
WaitForExit
或poll
haseexit
,您的UI将挂起,这正是因为您的代码实际上正在等待进程结束

您的UI只有一个线程,不能“多任务”。这就是为什么这些“处理”类型的操作应该在不同的线程中完成(或者,就像这里的情况一样,在不同的进程中),并在完成后向UI报告

例如:

' Handle Exited event and display process information.
Private Sub myProcess_Exited(ByVal sender As Object, ByVal e As System.EventArgs)
    'Do something in your UI
End Sub
在您的起始代码中:

getUpdate.EnableRaisingEvents = True
AddHandler getUpdate.Exited, AddressOf myProcess_Exited

当我使用WaitForExit时,我的应用程序会以某种方式暂停,就像listbox不更新一样,并且只有在WaitForExit之后才会恢复正常。我正在寻找一个替代方案,如果我可以检查我创建的进程是否仍在运行。