Application.Exit [英] Application.Exit

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

问题描述

我使用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:

一般情况下,主要方法是这样的,如何退出主功能正常,而无需调用Environment.Exit?

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);
        }
    }

在此先感谢, 乔治

thanks in advance, George

推荐答案

Application.Exit 真的只是询问消息循环非常轻柔。

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

如果你希望你的应用程序退出,最好的办法就是优雅地让出,并且干净地关闭任何额外的非后台线程。

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.

如果你想成为残酷... <一个href="http://msdn.microsoft.com/en-us/library/system.environment.exit.aspx"><$c$c>Environment.Exit Environment.FailFast 注意这是严酷的。 - 约等于杀死你自己的进程

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

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

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