运行 另一个应用 Process.Start()

Running another application with Process.Start()

我是 运行 应用程序 Test_A,从这个应用程序开始,我将使用以下代码启动另一个名为 Test_B 的应用程序:

Test_B.StartInfo.CreateNoWindow = True
Test_B.StartInfo.UseShellExecute = False
Test_B.StartInfo.FileName = "App_Test_B.exe"
Test_B.Start()

Test_A等待Test_B退出我运行这个循环:

Do Until Test_B.HasExited = True
   Application.DoEvents()
   System.Threading.Thread.Sleep(100)
Loop

我的问题是,这个Sleep(100)是否也会影响Test_B申请或只适用于Test_A

Test_ATest_B都是独立的进程。 Test_A 中发生的事情不会影响 Test_B,除非它通过某种 Interprocess Communication.

明确地与 Test_B 通信

顺便说一句,该循环不是等待进程结束的好方法。相反,您应该使用进程终止时引发的 Process.Exited event

Test_B.StartInfo.CreateNoWindow = True
Test_B.StartInfo.UseShellExecute = False
Test_B.StartInfo.FileName = "App_Test_B.exe"
Test_B.EnableRaisingEvents = True

AddHandler Test_B.Exited, AddressOf TestB_Exited

Test_B.Start()

在您代码的其他部分:

Private Sub TestB_Exited(sender As Object, e As EventArgs)
    'Do something when Test_B has exited.
End Sub