WPF 应用程序重启

WPF application restart

我必须重新启动一个应用程序。当我用谷歌搜索时,我发现 this 和其他几个建议此代码的人:

System.Diagnostics.Process.Start(Application.ResourceAssembly.Location); System.Windows.Application.Current.Shutdown();

但它所做的只是关闭应用程序。我在Visual Studio里面试过了,直接执行bin文件夹下的exe,结果总是一样。 该项目是一个 .NET Core WPF。 任何其他想法,或想法可能是什么问题?

你应该尝试获取进程而不是程序集,它可以return一个.dll.

重新启动当前应用程序:

var currentExecutablePath = Process.GetCurrentProcess().MainModule.FileName;
Process.Start(currentExecutablePath);
Application.Current.Shutdown();