博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C# 重新启动程序(并非重启计算机)

Posted on 2010-01-13 13:16  孙潇楠  阅读(839)  评论(2编辑  收藏  举报
 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();
        }

        /// <summary>
        /// 设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnConfig_Click(object sender, EventArgs e)
        {
            frmHikClientConfig frm = new frmHikClientConfig();
            if (frm.ShowDialog() == DialogResult.OK)
            {
                Application.ExitThread();
                Restart();
            }
        }