Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.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,我已通过system.diagnostics.process.start(“C:/process.exe”)启动了一个进程 现在我的问题是,如何在vb.net中终止同一进程,Start()方法返回一个进程对象。调用其Kill方法: Private WithEvents MyProcess As Process Private Sub MyProcess_Exited(ByVal sender As Object, ByVal e As System.EventArgs) Handles

我已通过system.diagnostics.process.start(“C:/process.exe”)启动了一个进程 现在我的问题是,如何在vb.net中终止同一进程,Start()方法返回一个进程对象。调用其Kill方法:

  Private WithEvents MyProcess As Process

  Private Sub MyProcess_Exited(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyProcess.Exited
    MyProcess = Nothing
  End Sub

  Private Sub RunIt()
    MyProcess = Process.Start("notepad.exe")
  End Sub

  Private Sub StopIt()
    If MyProcess IsNot Nothing Then MyProcess.Kill()
  End Sub
Start()方法返回一个进程对象。调用其Kill方法:

  Private WithEvents MyProcess As Process

  Private Sub MyProcess_Exited(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyProcess.Exited
    MyProcess = Nothing
  End Sub

  Private Sub RunIt()
    MyProcess = Process.Start("notepad.exe")
  End Sub

  Private Sub StopIt()
    If MyProcess IsNot Nothing Then MyProcess.Kill()
  End Sub

其他人提到了Kill方法来强制进程终止。您可能希望调用CloseMainWindow,以便应用程序有机会正常关闭。

其他人提到了强制进程终止的Kill方法。您可能希望调用CloseMainWindow,以便应用程序有机会正常关闭