Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProcessStartInfo.UseShellExecute = true and waiting for process exit

I want to use shell executable in order to respect user preferences of application to be started, but I also need to know when that particular application is closed.

Process editProcess = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = filename;
startInfo.Verb = "edit";
startInfo.UseShellExecute = true;
editProcess.StartInfo = startInfo;

// start the default editor
editProcess.Start();
editProcess.WaitForExit();

WaitForExit seems to return when the shell process exits and not when the real process exits.

Is there a better way of knowing when started application is exited than manually parsing registry, finding correct application to start and explicitly start that app without shell execute?

like image 430
mostlytech Avatar asked Nov 15 '22 07:11

mostlytech


1 Answers

Handle the process exited event:

editProcess.Exited += process_Exited;
like image 169
Dan Avatar answered May 01 '23 22:05

Dan