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

问题描述 投票:1回答:1

我正在运行应用程序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

vb.net process.start
1个回答
2
投票

Test_ATest_B都是独立的过程。在Test_A发生的事情不会影响Test_B,除非它通过某种Test_B明确地与Interprocess Communication沟通。

顺便说一句,该循环不是等待过程结束的好方法。相反,您应该使用在进程终止时引发的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
© www.soinside.com 2019 - 2024. All rights reserved.