zoukankan      html  css  js  c++  java
  • winfrom中Application.Restart()

    System.Windows.Forms.Application.Restart();方法系统实现自动重启。

                if (FrmDialog.ShowDialog(this, "确定退出登录吗?", "提示", false, false, false, null, DialogType.YesNo) == DialogResult.OK)
                {
                    System.Windows.Forms.Application.Restart();
                }

    花了接近一天的时间,才研究出来这个系统自动重启时好时坏的问题。  

    应用.net自带的Application.Restart();有时候重新启动好用,而有时就是起不来,特别启动次数多了和电脑比较老旧时老出现。查找了好多相关的资料,都没能尝试成功。

    但是不管怎样我觉得这个说的还算是对我有用粘贴过来。

      If Application.Restart is called from any thread in a normally run Windows Forms application, the application shuts down and restarts. 
    In a ClickOnce deployed application, this can be used to cause the application to restart after an update has been downloaded using the ApplicationDeployment class. 
    However, if you call Application.Restart from a non-UI thread (i.e a thread pool thread in the BackgroundWorker.DoWork event), the application is shut down but not restarted. 

    感觉网上很不赞成应用Application.Restart();方法的,因为,可能导致它不好用的原因很多,会很莫名其妙,但是系统确实就有这样的需求,因此,只能不得已而为之。

    这次解决的办法,我总结主要是这个原因,在系统要求自动重启的时候,首先要关闭原有的所有进程,但是重启的这个方法,会因为在没有完全关闭的时候就启动,这样方法本身冲突发生异常就会被关闭,因此,重新启动失败。最后,将Program中的启动线程挂起1秒,问题便解决了。

                //解决Restart方法冲突问题
                System.Threading.Thread.Sleep(1000);
  • 相关阅读:
    Automatically Display Menu on Hover
    WPF自学教程系列1:如何将WPF空间嵌套到Form窗口?
    NET中的内存管理,GC机制,内存释放过程. 转载
    C++ 初始化和赋值的区别
    2.尽量用const, enum, inline代替#define Prefer const, enum, inline to #define.
    1.视C++为一个语言联邦 View C++ as a federation of languages
    C++内存对齐
    C++ class和struct的区别
    redhat AS5 Samba服务配置
    windowsXP & 2003 加固
  • 原文地址:https://www.cnblogs.com/bit-by-bit/p/14307735.html
Copyright © 2011-2022 走看看