private async void RunWinUpdatesPage_Loaded(object sender, RoutedEventArgs e) { Log.Debug("RunWinUpdatesPage", $"Win Update Page Loaded; After reboot? : {resumeInstall}"); Loaded -= RunWinUpdatesPage_Loaded; if (resumeInstall) { await ResumeAfterRestart().ConfigureAwait(false); } else { ResetProgress(); StartInfiniteProgress("preparing..."); var prepared = await Prepare().ConfigureAwait(false); if (aborted || !prepared) { ResetProgress(); SetParagraphLook(checkParagrath, TextLook.Skipped); SetParagraphLook(downloadParagrath, TextLook.Skipped); SetParagraphLook(installParagrath, TextLook.Skipped); FinishAndProceed(); return; } //start with checking for updates right away winUpdateManager = new WinUpdatesManager(); //winUpdateManager = new DummyWinUpdateManager(); winUpdateManager.CheckCompleted += WinUpdateManager_CheckCompleted; winUpdateManager.ProgressChanged += WinUpdateManager_ProgressChanged; //checking reports no progress so indeterminate StartInfiniteProgress(""); SetParagraphLook(checkParagrath, TextLook.Processing); winUpdateManager.CheckForUpdates(); } }
async Task Cleanup() { //unregister all events //todo is this really necessary: considering that //this reference lives here in the Page only if (winUpdateManager != null) { winUpdateManager.CheckCompleted -= WinUpdateManager_CheckCompleted; winUpdateManager.DownloadCompleted -= WinUpdateManager_DownloadCompleted; winUpdateManager.InstallationCompleted -= WinUpdateManager_InstallationCompleted; winUpdateManager.ProgressChanged -= WinUpdateManager_ProgressChanged; //in case there is still somehting going on at the moment //todo can this cause problems? //winUpdateManager.AbortAll(); winUpdateManager.CleanUp(); winUpdateManager = null; } await WinServiceUtils.StopServiceAsync(WinUpdatesManager.WUA_SERVICE_NAME, 60000).ConfigureAwait(false); WinServiceUtils.TrySetStartupType(WinUpdatesManager.WUA_SERVICE_NAME, false); }