我只想问你关于如何“终止”正在运行的应用程序/进程的意见/建议是 C#
现在,我有以下代码:
Process myProcess;
private void btnOpen_Click(object sender, RoutedEventArgs e)
{
DirectoryInfo di = new DirectoryInfo(System.Environment.GetFolderPath(Environment.SpecialFolder.Programs));
myProcess = Process.Start(di + @"\Wosk\Wosk.appref-ms"); // opening a file coming for Startup Menu
}
private void btnClose_Click(object sender, RoutedEventArgs e)
{
myProcess.Kill(); // not working - Cannot process request because the process has exited
}
我也试过 myProcess.Close();但什么也没有发生。
最佳答案
你应该看看
A process can terminate independently of your code. If you started the process using this component, the system updates the value of HasExited automatically, even if the associated process exits independently.
关于C#/.NET : Closing another process outside the main window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2532202/