代码永远不会在退出时运行 [英] Code Never Runs Upon Exit

查看:79
本文介绍了代码永远不会在退出时运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个Winform问题.我想使用Environment.Exit(1)退出应用程序.但是,当我使用这种方法时,退出代码之前的代码不会执行.有什么想法吗?这是我的代码.只需注意一下,如果我省略Environement.Exit(1)代码,该代码将成功运行.

Hi all,

I have an issue with a winform. I would like to exit the application using Environment.Exit(1). However when I use this approach the code before the exit code does not execute. Any thoughts? Here is my code. Just as a note, the code runs successfully if I leave out the Environement.Exit(1) code.

public void ShowForm(System.Windows.Forms.Form frm, string id)
{
    frmMain=frm;
    this.Show();

    object empty = null;

    axW.Navigate("http://localhost:2124/Studiebogservice/_Ankomst/LabelPrint.aspx?id=" + id, ref empty, ref empty, ref empty, ref empty);

    for (; axW.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE; )
    {
        System.Windows.Forms.Application.DoEvents();
    }

    axW.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref empty, ref empty);

    Environment.Exit(1);
}

推荐答案

它可能确实提示运行,并准备了命令-但作为异步过程.然后是Environment.Exit并终止与应用程序相关的所有进程,包括您刚刚准备打印的进程.

Environment.Exit是重要的一步-这是一个异常终止,它会关闭所有内容,而无需等待它们完成,保存数据或执行其他任何操作.
It probably does get cued to run, and the commands for it are prepared - but as an asynchronous process. Then along comes Environment.Exit and terminates all processes associated with the application, including those you have just prepared to print.

Environment.Exit is a big step - it is an abnormal termination, and it shuts everything down, without waiting for them to finish, save data, or do anything else.


这篇关于代码永远不会在退出时运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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