检测单个Windows进程退出事件C#
好的,我还有一个,现在我正在做一个按钮,叫做installbtn 现在我的代码中有检测单个Windows进程退出事件C#,c#,process,exe,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[] pcc
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”)
,然后在安装完成后重新加载应用程序。不确定是否可能,但我会感谢您的帮助
谢谢Shaun。
启动
返回一个进程
对象,您可以在该对象上等待(或启动等待的线程等)。启动
返回一个进程
对象,您可以在该对象上等待(或启动等待的线程等)。您可以使用
WaitForExit()重载用于使当前线程等待
直到相关进程终止。此方法指示
进程组件为进程等待无限长的时间
和要退出的事件处理程序
你可以用
WaitForExit()重载用于使当前线程等待
直到相关进程终止。此方法指示
进程组件为进程等待无限长的时间
和要退出的事件处理程序
进程有一个退出的事件,可以使用该事件检查这两个链接:1-;2-进程有一个退出的事件,可以使用该事件检查这两个链接:1-;2-你能给我举个例子吗?你能给我举个例子吗?我放了一个try-catch块,它给了我一个消息,没有与对象相关的进程。我正试图从64位计算机中定位win32进程。之后,它继续正常运行其余代码。当它启动时,存储在字节中的内部exe正在启动,但它需要等待程序和进程正常关闭。我可以使源代码可用,因为它是我制作的免费软件。@Shaun'Shorty'Cassidy只是对代码做了一个小改动,在调用process.WaitForExit()之前调用process.Start(),是的,这很有效,现在一切都好了,谢谢Kurubaran,我会确保在我的源代码中归功于你。@Shaun'Shorty'Cassidy很高兴它帮助了你。我加入了一个try-catch块,它给了我消息,没有与对象相关的进程。我正试图从64位计算机中定位win32进程。之后,它继续正常运行其余代码。当它启动时,存储在字节中的内部exe正在启动,但它需要等待程序和进程正常关闭。我可以使源代码可用,因为它是我制作的免费软件。@Shaun'Shorty'Cassidy刚刚对代码做了一个小改动,在调用process.WaitForExit()之前调用process.Start()。是的,现在一切都好了,谢谢Kurubaran。我会确保在我的源代码中信任你。@Shaun'Shorty'Cassidy很高兴它帮助了你。
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
process.StartInfo = startInfo;
startInfo.FileName = exeToRun;
process.Start();
process.WaitForExit();