c#如何用一个程序打开另一个程序(如:窗体的注销重启)

实现步骤

1.定义事件

2.在事件方法中调用重启方法

3.重启方法实现(重点)

具体实现

1.定义事件

this.btnLoginOut.ItemClick -= btnLoginOut_ItemClick;

2.在事件方法中调用重启方法

 void btnLoginOut_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
             try
            {
                Application.Exit();//释放关掉当前打开的所有进程
            }
            finally
            {
                ReStartWin();//调用重启的另一个程序
            }
        }

3.重启方法实现

 private void ReStartWin()
        {
            System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
            //设置外部程序名
            info.FileName = "Mobot.TeamFoundation.Client.Win.exe";
            //设置外部程序的工作目录为
            info.WorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            //正常方式启动
            info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
            //声明一个程序类
            System.Diagnostics.Process Proc;
            try
            {
                Proc = System.Diagnostics.Process.Start(info);
                System.Threading.Thread.Sleep(500);
            }
            catch(System.ComponentModel.Win32Exception)
            {
                return;
            }

        }
原文地址:https://www.cnblogs.com/lqsilly/p/silly.html