定义一个重新启动的类:
class Relogin { public void Restart() { Thread thtmp = new Thread(new ParameterizedThreadStart(run)); object appName = Application.ExecutablePath; Thread.Sleep(1000); thtmp.Start(appName); } private void run(Object obj) { Process ps = new Process(); ps.StartInfo.FileName = obj.ToString(); ps.Start(); } }
调用:
new Relogin().Restart();
如果要关闭当前已启动的程序就在调用重启程序的前面加一句:
Application.ExitThread();