Process does not close in task manager

Asked

Viewed 806 times

1

I have the following code snippet to close my winform application:

private void frmAgent_FormClosing(object sender, FormClosingEventArgs e){          
        if (MessageBox.Show("Deseja realmente fechar o sistema?", "Atenção!",    MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
            != DialogResult.Yes)
        {
            e.Cancel = true;
        }
    }

The application closes, but unfortunately the process is still running in the task manager. What can I do to kill the process by closing the application ?

  • 1

    frmAgent is the only application form? How is your class containing the method Main?

1 answer

0


You could call the method Environement.Exit(0) that directly terminates the process of your current thread (your application in this case), for example:

private void frmAgent_FormClosing(object sender, FormClosingEventArgs e)
{          
    if (MessageBox.Show("Deseja realmente fechar o sistema?", "Atenção!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
    {
        e.Cancel = true;
        return;
    }

    Environement.Exit(0);
}

There is also the possibility to call the method Application.Exit(), that closes all threads of your application and later the process. You can test it too. I recommend reading of this link.

  • He couldn’t, he was having trouble with it. This event is just triggered because it is coming out of the application (or at least it is what it seemed, anyway it can’t come out this way). http://answall.com/q/47890/101

  • It worked perfectly, thank you very much Felipe Oriani !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.