Detect if launched process has been closed

岁酱吖の 提交于 2019-12-13 19:13:45

问题


c# I want to Detect if a launched program has been closed. I am currently launching it with the command

 Process.Start(Environment.CurrentDirectory + @"\Card Downloader.exe"); 

Has anyone got a way of doing this perhaps using a different launcher?


回答1:


The Process.Start() method returns a Process object. Assign it to a variable and call WaitForExit() on.

Source: http://msdn.microsoft.com/en-us/library/fb4aw7b8.aspx




回答2:


The Process.Start method returns a Process instance. On this instance you could use some of the available methods such as WaitForExit or subscribe to the Exited event which will be triggered when this process ends.

var process = Process.Start(Environment.CurrentDirectory + @"\Card Downloader.exe"); 
process.Exited += (sender, e) =>
{
    // this will be called when the process exists
};



回答3:


You can use Process.Exit event

var myProcess = new Process();
...
myProcess.Exited += new EventHandler(myProcess_Exited);
myProcess.Start();


来源:https://stackoverflow.com/questions/15320836/detect-if-launched-process-has-been-closed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!