wpf - Process on kill event C# -


i'm using c# wpf.
have list of process run them start() command.
want know when user exit process , catch event.
i'm tried:

myprocess.startinfo.filename = filename; myprocess.enableraisingevents = true; myprocess.exited += new eventhandler(myprocess_exited); myprocess.start(); 

*myprocess process object.
problem after start() command application closed , myprocess_exited callback called.
mistake?

the reason behaviour is, exe start closing or crahsing directly after starting it. example if exe console application not have user-input or thing else. try code notepad.exe , you'll see works.

take @ ironpython code, .net code application (only easier testing purpose):

from system.diagnostics import process

def on_exit(s, e):     print ('exited')  process = process() process.startinfo.filename = "c:\\windows\\system32\\notepad.exe" process.enableraisingevents = true process.exited += on_exit; process.start() 

exit called if close notepad.

edit

if want detected app closed/exited, case sender object process , access it's filename on startinfo. example:

private void onexited(object sender, eventargs, e) {     var process = (sender process);     console.writeline(process.startinfo.filename); } 

hope helps.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -