Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I properly close a winforms application in C#?

Tags:

c#

winforms

exit

I ran the .exe for my program from the debug folder. It worked, but when I closed it, I discovered that it was still listed on the processes list in the Task Manager.

I figure I must've forgotten a step, since it's my first winforms program.

like image 684
Slateboard Avatar asked Mar 10 '10 03:03

Slateboard


1 Answers

As long as the code in your Main method looks like this:

Application.Run(new MainForm());

Then you should be OK (assuming "MainForm" is the name of your main form). WinForms will exit the process when the form you pass in to Application.Run closes.

Otherwise you can call Application.Exit() yourself in your form's "Closed" event handler.

like image 90
Dean Harding Avatar answered Oct 04 '22 22:10

Dean Harding