我如何重新启动我的应用程序? [英] hwo do i restart my application?

查看:70
本文介绍了我如何重新启动我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

我知道要重新启动应用程序Application.Restart(),但是在恢复已处置的表单的另一种尝试中,我有一些有趣的事情:

I know to restart application, Application.Restart() but i have something funny in an alternative attempt to reinstatiate disposed forms:

以下代码会在我的应用程序中处理所有表单:

the follwong code dispose all forms in my application:

 List<Form> frmCol = new List<Form>();


        if (dr == DialogResult.Yes)
        {
          foreach (Form item in Application.OpenForms)
          {
            frmCol.Add(item);
          }

          //this will dispose all forms
          foreach (Form item in frmCol)
          {
            item.Dispose();
          }
        }

然后在上述代码之后的以下几行中,尝试撤消一个登录表单的实例,但它会创建并显示它一秒钟,然后关闭该应用程序.但是我没有从任何地方调用application.exit():

Then in the following lines right after the above code, attempts to recreaet an instance of a the login form but it creates and shows it for a fraction of a second then shut downs the application. But i didnt call application.exit() from any where:

 if (dr == DialogResult.Yes)
        {
          foreach (Form item in Application.OpenForms)
          {
            frmCol.Add(item);
          }

          //this will dispose all forms
          foreach (Form item in frmCol)
          {
            item.Dispose();
          }
        }


        //calls to clear the entry on session table
        myUserAccount.str_operator = statusUserName.Text;

        byte b = myUserAccount.LogOffUser();

        if (b != 0)
        {
          ClientOperations.MessageHandler.ShowErrorMessage("Application error: Log off failed");
        }
        else
        {
          //calls login form: since i dispose all forms 
          myLogin = new frmLogin(); //assume myLogin was declared gloablly
myLogin.Show(); }

else块中的代码仅工作一秒钟,然后整个应用程序关闭.当我不事件调用Application.Exit()时,怎么办?即使重新创建myLogin对象,它也会保留myLogin对象吗?

the code in the else block works only for a fraction of a second then the whole application shuts down. How comes this possible when i dont event call Application.Exit() and what it does keep the myLogin object even after i recreate it?

感谢

推荐答案

如果使用Application.Run打开了表单,则会自动添加Closed事件处理程序.它会调用ExitThread.

If you opened a form with Application.Run, a Closed event handler is automatically added. It calls ExitThread.


这篇关于我如何重新启动我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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