Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hook closing applications

Tags:

c#

.net

windows

From my C# application, I'm trying to get notification from another (specific) application when it is closing (just when its process ends). From what I found, hook on this process is a possible solution, but I didn't managed to make it work. Can anyone help me on that or propose another solution.

like image 771
SWE Avatar asked Mar 26 '26 10:03

SWE


1 Answers

You can use the Process class to do this, specifically, its Exited event:

var process = Process.GetProcessesByName("notepad").Single();
// or Process.GetProcessById() if you have the ID
process.EnableRaisingEvents = true;
process.Exited += YourHandler;
like image 176
svick Avatar answered Mar 27 '26 23:03

svick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!