【问题标题】:Running another application with Process.Start()使用 Process.Start() 运行另一个应用程序
【发布时间】:2017-12-20 12:30:44
【问题描述】:

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

【问题讨论】:

  • 对 B 没有副作用。请改用 Process.Exited 事件。

标签: vb.net process.start


【解决方案1】:

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

【讨论】:

  • 很棒的信息。非常感谢。
  • @IGM :很高兴我能帮上忙,欢迎来到 Stack Overflow!如果我的回答解决了您的问题,请按我帖子左侧的勾选/复选标记将其标记为已接受。更多信息请参考:How does accepting an answer work?
猜你喜欢
  • 2012-05-19
  • 1970-01-01
  • 1970-01-01
  • 2011-09-02
  • 2011-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-31
相关资源
最近更新 更多