Know if the application was terminated by the task manager

4

Is my application aware that it is being terminated by the task manager?

If the user is to terminate my application through the task manager, does my application detect this completion and perform some tasks before it is finished?

Does anyone have any idea how I can do this?

NOTE: My application is running direct.

NOTE 2: My application is in WPF .

    
asked by anonymous 08.07.2015 / 18:30

2 answers

4

There is no reliable way to do this. The user can always end up whatever he wants.

In some situations it is possible to capture a Windows message and do something. But there is no guarantee that this message will be sent by Windows. It depends on how the user is terminating the process. It does not even have to be the task manager. There's an article about this from Raymond Chen .

Take a look at this Process.WaitForExit documentation, help but I have questions.

Question in the SO about it .

In short: forget it.

    
08.07.2015 / 18:43
5

You can check through the FormClosingEventArgs event.

See the example below. It's working in my application.

    private void frmLogin_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (e.CloseReason == CloseReason.TaskManagerClosing)
        {
            MessageBox.Show("Fechou pelo gerenciador de tarefas...");
        }
    }

See the documentation.

link

    
08.07.2015 / 18:59