Application.Exit()无法正常工作 [英] Application.Exit() not working

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

问题描述

static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Exit();
            Application.Run(new Form1());
        }

为什么在调用Application.Exit()之后,应用程序没有立即退出?在此行之后,仍然显示Form1.如何立即退出应用程序.谢谢.

Why after calling Application.Exit(), application doesn't exit immediately? After this line, Form1 still shows. How to exit application immediately. Thanks.

* 注意: *这仅是示例.在显示表单之前,我会处理一些功能.在函数中,我有一个命令代码来调用Application.Exit(),但我想知道为什么应用程序不会立即退出.

*Notes:*this is only an example. I handle some functions before showing form. And in functions, I have a command code to call Application.Exit() but I wonder why application doesn't exit immediately.

我正在使用.NET Framework 4.0

I'm using .NET Framework 4.0

推荐答案

应用程序.退出说:

通知所有消息泵它们必须终止,然后在处理完消息后关闭所有应用程序窗口.

Informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed.

问题在于,直到您调用运行"并创建表单之后,您的应用程序的消息泵才会启动.

The problem is the message pump for your application wont start until after you call Run and the Form is created.

通常在消息循环内调用Exit方法,并强制Run返回.

The Exit method is typically called from within a message loop, and forces Run to return.

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

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