Hi,
If you use Windows Forms, then you can use the
Form.FormClosing[
^] event:
void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.TaskManagerClosing)
{
}
else if (e.CloseReason == CloseReason.WindowsShutDown)
{
}
else if (e.CloseReason == CloseReason.UserClosing)
{
}
else
{
}
}
Here you'll find all enum fields of the
CloseReason
enum:
http://msdn.microsoft.com/en-us/library/system.windows.forms.closereason.aspx[
^]
If you use WPF, use the
Window.Closing[
^] event.
But if Task Manager closes the application, then the function will be called only if the user clicks on the "End Task" button. Clicking on the "End Task" button is similar to the
Process.Close[
^] method. If the user clicks on the "End Process" button, then the process
will be stopped immediately, then you can't deallocate resources. Clicking on the "End Process" button is similar to the
Process.Kill method[
^]
Hope this helps.