如何正确关闭在C#WinForms应用程序? [英] How do I properly close a winforms application in C#?

查看:159
本文介绍了如何正确关闭在C#WinForms应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跑了的.exe从debug文件夹我的计划。它的工作,但是当我关闭了它,我发现它仍然列在任务管理器进程列表中。

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.

我想我一定是忘了一步,因为这是我第一次的WinForms程序。

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

推荐答案

只要在你的主代码方法是这样的:

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

Application.Run(new MainForm());



这时你应该确定(假设的MainForm是你的主要形式的名称)。当窗体你传递给 Application.Run 关闭的WinForms将退出的过程。

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.

否则,你可以叫 Application.Exit()自己在窗体的关闭事件处理程序。

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

这篇关于如何正确关闭在C#WinForms应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆