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

丶灬走出姿态 提交于 2019-11-28 02:51:13

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/2414244/how-do-i-properly-close-a-winforms-application-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!