您的位置:首页 > 移动开发

.net application.restart() 系统实现自动重启

2011-01-20 14:10 786 查看
  花了整整一天的时间,才研究出来这个系统自动重启时好时坏的问题。

  应用.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.2秒,问题便解决了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐