花了整整一天的時間,才研究出來這個系統自動重啟時好時壞的問題。
應用.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秒,問題便解決了。
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。