C# 重启程序的方法

    C# 中一般重启exe程序有以下三种方法:

    方法一:使用Restart()方法, Restart()方法需要引用System.Windows.Forms,并在Application类中,而Application.Current.Shutdown();则需要引用System.Windows。

System.Windows.Forms.Application.Restart();
Application.Current.Shutdown();

**************************************************************************************************************

    方法二:使用System.Diagnostics.Process.Start()

System.Reflection.Assembly.GetEntryAssembly();
string startpath = System.IO.Directory.GetCurrentDirectory();
System.Diagnostics.Process.Start(startpath + “\\xxx.exe”);
Application.Current.Shutdown();

**************************************************************************************************************

    方法三:使用Process方式

Process p = new Process();
p.StartInfo.FileName = System.AppDomain.CurrentDomain.BaseDirectory + “xxx.exe”;
p.StartInfo.UseShellExecute = false;
p.Start();
Application.Current.Shutdown();

**************************************************************************************************************

    注意:首先System.Windows.Forms中的Application是没有Current的;而Current是在System.Windows中的;如果你的WPF项目中没有引用System.Windows.Forms,则直接使用Application.Current.Shutdown();即可,因为新建WPF程序时,默认的就会把System.Windows添加到引用项中;如果你引用中同时包含System.Windows和System.Windows.Forms程序集,需要使用指定的命名空间或者作用域System.Windows.Application.Current.Shutdown();

**************************************************************************************************************

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值