c implements the method of automatically restarting a program after exiting it

  • 2020-05-12 02:58:55
  • OfStack

Examples are as follows:


// Triggers the exit program event 
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();
    }
 

Note: the namespace for Process is: System.Diagnostics;


Related articles: