Process does not close in the task manager

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 still runs in the task manager. What can I do to kill the process when I close the application?

    
asked by anonymous 28.01.2015 / 13:17

1 answer

0

You could call the Environement.Exit(0) method that directly terminates the process of your current thread (your application in 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 of calling the Application.Exit() method, which closes all threads in your application and then the process. You can test it too. I recommend reading from this link .

    
28.01.2015 / 14:34