Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to gracefully exit this application?

In order to not show a form in C#.NET when first starting the application I have this:

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        SomethingForm frmSomething = new SomethingForm();

        Application.Run();
    }

It is a one form application and the SomethingForm is the the parent form which has a Button to exit which currently calls the following Application.ExitThread();. This button is the only way to exit the application.

Now I know this is not graceful termination, but it was the only way I could get it to work when testing. It's now causing some problems with leaving the icon in the system tray after exit.

So how do I GRACEFULLY terminate this application?

like image 854
Cheetah Avatar asked Nov 25 '25 23:11

Cheetah


1 Answers

or using:

Application.Exit() 

anywhere in the code.

or

System.Environment.Exit(-1);
like image 78
Carlos Quintanilla Avatar answered Nov 27 '25 12:11

Carlos Quintanilla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!