key*_*rdP 28
我认为WPF中没有像WinForms中那样的直接方法.但是,您可以使用Windowns.Form
命名空间中的方法,如下所示:(您可能需要添加对System.Windows.Form
程序集的引用)
System.Windows.Forms.Application.Restart();
System.Windows.Application.Current.Shutdown();
Run Code Online (Sandbox Code Playgroud)
小智 11
编码
Process.Start(Application.ResourceAssembly.Location);
Run Code Online (Sandbox Code Playgroud)
不适用于 .NET Core 3.1 应用程序。而是使用
using System.Diagnostics;
using System.Windows;
...
Process.Start(Process.GetCurrentProcess().MainModule.FileName);
Application.Current.Shutdown();
Run Code Online (Sandbox Code Playgroud)
这也适用于 .NET Framework 应用程序。
Moh*_*dil 10
以下是我找到的最佳解决方案,您不需要添加对System.Windows.Forms的引用,而是需要添加System.Diagnostics
已经具有对其程序集的引用的命名空间:
Process.Start(Application.ResourceAssembly.Location);
Application.Current.Shutdown();
Run Code Online (Sandbox Code Playgroud)