我想在C#中单击按钮关闭正在运行的exe.出现错误
本文关键字:运行 exe 错误 单击 按钮 | 更新日期: 2023-09-27 17:57:30
我想在C#中单击按钮关闭正在运行的exe。。但我有
进程已退出,因此请求的信息不可用。
我的代码:
Process nynprocess = new Process();
private void button2_Click(object sender, EventArgs e)
{
string str = @"C:'Program Files'ShareX'ShareX";
nynprocess.StartInfo.FileName = str;
nynprocess.Start();
}
private void button3_Click(object sender, EventArgs e)
{
nynprocess.CloseMainWindow();
nynprocess.Kill();
nynprocess.WaitForExit();
}
尝试使用此
// Close process by sending a close message to its main window.
nynprocess.CloseMainWindow();
// Free resources associated with process.
nynprocess.Close();