问题
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