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         }

 

posted @ 2018-10-11 16:18  ProvokeXun  阅读(12004)  评论(0编辑  收藏  举报