Hi TZacks-2728,
The task manager calls the Windows API ExitProcess to kill the process.
For WinForms applications, you can try Application.ApplicationExit event which occurs when the application is about to shut down.
You must attach an event handler to the ApplicationExit event to send mail before the application stops running.
// Handle the ApplicationExit event to know when the application is exiting.
Application.ApplicationExit += new EventHandler(this.OnApplicationExit);
For more details, you can refer to the example in the document.
And the code example using the forked process in the link provided by periczeljkosmederevo is also a good suggestion.
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.