C# 程序实现自重启(重新启动自己)。

 private void Restart()
        {
            Thread thtmp = new Thread(new ParameterizedThreadStart(run));
            object appName = Application.ExecutablePath;
            Thread.Sleep(2000);
            thtmp.Start(appName);
        }
        private void run(Object obj)
        {
            Process ps = new Process();
            ps.StartInfo.FileName = obj.ToString();
            ps.Start();
        }
        /// 
        /// 设置
        /// 
        /// 
        /// 
        private void btnConfig_Click(object sender, EventArgs e)
        {
            frmHikClientConfig frm = new frmHikClientConfig();
            if (frm.ShowDialog() == DialogResult.OK)
            {
                Application.ExitThread();
                Restart();
            }
        }

//============或者(下面的没测试)
clossing事件中,用Process.Start启动一下自己就可以。   
    
    
  在主窗体的closing事件中,加入如下代码:   
    
  if   (   MessageBox.Show("要重新启动嘛?","提示",   MessageBoxButtons.YesNoCancel,   
  MessageBoxIcon.Question)   ==   DialogResult.Yes)   
    
  System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);

你可能感兴趣的:(Csharp,.net)