C#退出程序自动重新启动
有时修改了配置文件,需要关闭软件重新启动进行确认。
--------------------------------------------------------------------------------
//触发退出程序事件 private void button1_Click(object sender, EventArgs e) { Application.ExitThread(); Thread thtmp = new Thread(new ParameterizedThreadStart(run)); object appName = Application.ExecutablePath; Thread.Sleep(1); thtmp.Start(appName); } private void run(Object obj) { Process ps = new Process(); ps.StartInfo.FileName = obj.ToString(); ps.Start(); }
注:Process 的命名空间为:System.Diagnostics;
Thread的命名空间为System.Threading;