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

本文探讨了.NET应用程序中使用Application.Restart()方法导致的重启不稳定问题。指出从非UI线程调用此方法会导致重启失败,并提供了解决方案:确保所有进程关闭后再重启,通过在重启前暂停程序一段时间来避免冲突。

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

  应用.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秒,问题便解决了。

转载于:https://www.cnblogs.com/zhonghuafu/archive/2011/01/20/1940171.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值