C# 如何實現WinForm程序自重啟(重新啟動自己)


  1.  重啟的時間間隔方法
 1 private void Restart()
 2 
 3         {
 4 
 5             Thread thtmp = new Thread(new ParameterizedThreadStart(run));
 6 
 7             object appName = Application.ExecutablePath;
 8 
 9             Thread.Sleep(2000);
10 
11             thtmp.Start(appName);
12 
13         }
14 
15         private void run(Object obj)
16 
17         {
18 
19             Process ps = new Process();
20 
21             ps.StartInfo.FileName = obj.ToString();
22 
23             ps.Start();
24 
25         }

 

            2.單擊按鈕執行重啟

      

 1  private void btnConfig_Click(object sender, EventArgs e)
 2 
 3         {
 4 
 5             frmHikClientConfig frm = new frmHikClientConfig();
 6 
 7             if (frm.ShowDialog() == DialogResult.OK)
 8 
 9             {
10 
11                 Application.ExitThread();
12 
13                 Restart();
14 
15             }
16 
17         }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM