C#程式重新開機(程式重啟,非系統重啟)

C#程式重新開機(程式重啟,非系統重啟)

C#程式重新開機(程式重啟,非系統重啟)


 

資料來源: https://harde.org/blog/2009/08/c%E7%A8%8B%E5%BA%8F%E9%87%8D%E6%96%B0%E5%90%AF%E5%8A%A8%EF%BC%88%E7%A8%8B%E5%BA%8F%E9%87%8D%E5%90%AF%EF%BC%8C%E9%9D%9E%E7%B3%BB%E7%BB%9F%E9%87%8D%E5%90%AF%EF%BC%89.html

 

//重啟程式
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();
}

調用也很簡單

private void btn_restart_Click(object sender, EventArgs e)
{
Application.ExitThread();
Restart();
}

 


 


發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *