Вопрос

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?

Это было полезно?

Решение 2

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

Другие советы

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
};

You can use Process.Exit event

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

You need to subscribe to the process Exited event, but also set the EnableRaisingEvents flag to true.

var process = Process.Start(Environment.CurrentDirectory + @"\Card Downloader.exe");
process.EnableRaisingEvents = true;
process.Exited += (sender, e) =>
{
    ...
};

If you don't set the flag, the event is raised only if the process is closed during or before the user has performed a call to the HasExited property, according to MSDN.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top