我有一个 WPF 应用程序在后台更新自身(通过 Squirrel.Windows),这是通过以下代码完成的:
var restartApp = false;
using (var mgr = new UpdateManager(@"http://wintst01:8282/unidealoffice/starter"))
{
var re = await mgr.UpdateApp(DownloadProgress);
if (re == null)
{
Debug.WriteLine("NULL");
}
else
{
MessageBox.Show($"Applicatie is bijgewerkt en dient herstart te worden\nNieuwe versie: {re.Version}", "Update");
restartApp = true;
}
}
if (restartApp)
{
UpdateManager.RestartApp();
}
此代码位于OnStartup()
This App.xaml.cs
is an Async and Await 调用中,因此它将在后台完成。现在我想知道在我关闭我的应用程序之前是否有可能我可以查看启动的这个线程是否仍在运行。如果是这样我无法关闭应用程序但我想隐藏任务栏中的图标并最小化应用程序。所以当它完成时我仍然可以更新我想关闭应用程序......
我希望有人能指出我正确的方向。
更新:这是我在 App.xaml.cs 中的 OnStartup 的完整代码
protected override async void OnStartup(StartupEventArgs e)
{
this.Dispatcher.UnhandledException += Dispatcher_UnhandledException;
for (int i = 0; i < e.Args.Length; i++)
{
if (e.Args[i].ToLower() == "/ForceInstall".ToLower() || e.Args[i].ToLower() == "-ForceInstall".ToLower() || e.Args[i].ToLower() == "-F".ToLower() || e.Args[i].ToLower() == "/F".ToLower())
{
ApplicationConstants.Instance.ForceInstall = true;
}
}
base.OnStartup(e);
var restartApp = false;
using (var mgr = new UpdateManager(@"http://wintst01:8282/unidealoffice/starter"))
{
var re = await mgr.UpdateApp(DownloadProgress);
if (re == null)
{
Debug.WriteLine("NULL");
}
else
{
MessageBox.Show($"Applicatie is bijgewerkt en dient herstart te worden\nNieuwe versie: {re.Version}", "Update");
restartApp = true;
}
}
if (restartApp)
{
UpdateManager.RestartApp();
}
}
我想要做的是让 Squirrel 确定是否有更新,他们将自动下载所有必要的文件并在重新启动应用程序后应用它们。但是因为这个应用程序是另一个应用程序的某种启动器,它将检查这个应用程序的更新并安装(解压缩)它们,它会在安装完成并启动安装的应用程序后自行关闭。但是,如果启动应用程序仍在自我更新,则无法关闭并重新启动它。