700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > c#如何用一个程序打开另一个程序(如:窗体的注销重启)

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

时间:2021-06-29 22:33:00

相关推荐

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(ponentModel.Win32Exception){return;}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。