申请.退出 [英] Application.Exit

查看:21
本文介绍了申请.退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 VSTS 2008 + .Net 3.5 + C# 来开发 Windows 窗体应用程序.我的困惑是,似乎 Application.Exit 不会强制应用程序终止?如果不是,我应该调用哪个方法来使应用程序终止?

I am using VSTS 2008 + .Net 3.5 + C# to develop Windows Forms application. My confusion is, seems Application.Exit does not force application to terminate? If not, which method should I call to make application terminate?

编辑 1:

通常main方法是这样的,如何不调用Environment.Exit优雅地退出Main函数?

Normally the main method is like this, how to exit Main function gracefully without calling Environment.Exit?

    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        try
        {
            Application.Run(new Form1());
        }
        catch (Exception ex)
        {
            Console.WriteLine (ex.Message);
        }
    }

提前致谢,乔治

推荐答案

Application.Exit 真的只是很温和地询问消息循环.

Application.Exit really just asks the message loop very gently.

如果您希望您的应用退出,最好的方法是优雅地退出 Main,并彻底关闭所有其他非后台线程.

If you want your app to exit, the best way is to gracefully make it out of Main, and cleanly close any additional non-background threads.

如果你想变得残酷... Environment.ExitEnvironment.FailFast?注意这很苛刻 - 与杀死自己的 Process 大致相同.

If you want to be brutal... Environment.Exit or Environment.FailFast? note this is harsh - about the same as killing your own Process.

这篇关于申请.退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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