C#程序重新启动(程序重启,非系统重启)
今天做练习时遇到一个问题,程序重启。
网上Google一番,找到了一下代码,用起来很方便。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | //重启程序 private void Restart() { System.Threading.Thread thtmp = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(run)); object appName = Application.ExecutablePath; System.Threading.Thread.Sleep(2000); thtmp.Start(appName); } private void run(Object obj) { System.Diagnostics.Process ps = new System.Diagnostics.Process(); ps.StartInfo.FileName = obj.ToString(); ps.Start(); } |
调用也很简单
1 2 3 4 5 | private void btn_restart_Click(object sender, EventArgs e) { Application.ExitThread(); Restart(); } |

没有评论▼