使用C#重启应用程序

如何使用C#重启我的WPF应用程序?

我不认为WPF中存在直接的方法,就像在WinForms中一样。 但是,您可以使用Windowns.Form命名空间中的方法,如下所示:(您可能需要添加对System.Windows.Form程序集的引用)

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

以下是我找到的最佳解决方案,您不需要添加对System.Windows.Forms的引用,而是需要添加命名空间System.Diagnostics ,您已经对其程序集进行了引用:

 Process.Start(Application.ResourceAssembly.Location); Application.Current.Shutdown(); 

您可以使用Windows API代码包的重新启动和恢复API。 请注意,这是一个新的API,因此它只适用于当前的操作系统(即:Windows 7)。