c# - 检测单个 Windows 进程退出事件 C#

标签 c# process exe

好吧,我有另一个,现在我正在处理一个按钮,在代码中称为 installbtn。

现在我的代码中有。

private void installbtn_Click(object sender, EventArgs e)
        {
// Access the internal exe resource pcc - the pcc is Path Copy Copy, which i am using as a
// requirement to use this software
   byte[] pccFile = Properties.Resources.pcc;  

// The resource pcc.exe as a binary called pcc which is then used as a byte called pccFile  
   string pccExe = Path.Combine(Path.GetTempPath(), "pcc.exe");  
// The Executable and its filename + Extenstion
   using (FileStream exeFile = new FileStream(pccExe, FileMode.Create))
   exeFile.Write(pccFile, 0, pccFile.Length);
// Write the file to users temp dir
   Process.Start(pccExe);

// Start the Installer
   installbtn.Text = "Installing...";
   StatusLabel1.Text = "Installing PCC Now...";
// Indicate on the form, the current process status.


// Here i want the application to check if pccExe has closed
// after the user has installed the component and its process "pcc.exe" exits
   MessageBox.Show("Module Installed /r/nPlease Start the Application", "Application Module Installed");
   installbtn.Text = "Restart Now!";
   StatusLabel1.Text = "Please Restart the Application";
// and if it has then show a message box and reflect in the form
// i want it to quit and restart the application after the message box is closed
}

现在,当安装程序完成时,我希望能够检测到安装程序何时在安装后关闭 ("pcc.exe"),然后在关闭后重新加载应用程序。不确定是否可行,但我将不胜感激。

谢谢肖恩。

最佳答案

你可以使用 Process.WaitForExit()

The WaitForExit() overload is used to make the current thread wait until the associated process terminates. This method instructs the Process component to wait an infinite amount of time for the process and event handlers to exit

Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
process.StartInfo = startInfo;

startInfo.FileName = exeToRun;    
process.Start();
process.WaitForExit();

关于c# - 检测单个 Windows 进程退出事件 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25602508/

相关文章:

windows - 检查 .exe 文件的权限级别

jar - 一个独立的 (Windows) JRE?

python - 如何从 Python 调用 Windows .exe 文件、输入参数并获取文件输出?

c# - 如何将字符串放入文化不变的桶中?

c# - 如何 "enable ' 从与我的应用程序相同的位置下载先决条件'”

多种类型的 C# XML 列表

java - 只有在通过 java 完成进程后,我的代码才会继续

c# - 没有 WaitForExit() 的 using 语句中的进程会发生什么情况?

java - 进程和退出代码

c# - 使用反射创建测试对象