Jam
Jam

Reputation: 101

How can I show MessageBox with suggestion of saving changes when I'm killing program from task manager?

I'm making a program and want show MessageBox with suggestion of saving changes, when I'm trying to kill it from task manager. How can I do it?

Upvotes: 0

Views: 58

Answers (3)

Beldi Anouar
Beldi Anouar

Reputation: 2180

In your principal form you can use even FormClosing as :

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {

            DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo);
            if(dialogResult == DialogResult.Yes)
            {
                //do something
            }
            else if (dialogResult == DialogResult.No)
            {
                e.Cancel=true ;
            }
     }

Upvotes: 0

RealSollyM
RealSollyM

Reputation: 1530

When killing an application from Task Manager you are simply terminating the application without continuing with the code. This means no more code execution. That cannot be handled.

It's like telling an employee "you are fired with immediate effect, pack and leave now" but still expect them to finish writing the application that will take 6 months to complete.

Upvotes: 2

SᴇM
SᴇM

Reputation: 7213

There is NO way you can execute any code in your application when it is being Killed by operating system or user. That's why its called Killing.

Upvotes: 1

Related Questions