From 95962bf20386c86035daf201658dedfdd1321eb9 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Sun, 22 Feb 2026 16:06:52 +0100 Subject: [PATCH] Add CheckForUpdateAsync method for manual update checks and update docs --- AlwaysUpToDate/DownloadManager.cs | 20 +++++++++++++++++++- README.md | 7 +++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/AlwaysUpToDate/DownloadManager.cs b/AlwaysUpToDate/DownloadManager.cs index 8b920e5..dbefa5b 100644 --- a/AlwaysUpToDate/DownloadManager.cs +++ b/AlwaysUpToDate/DownloadManager.cs @@ -138,7 +138,7 @@ namespace AlwaysUpToDate updateTimer.Start(); } - UpdateTimer_Elapsed(null, null); + _ = CheckForUpdateInternalAsync(); } /// @@ -166,7 +166,25 @@ namespace AlwaysUpToDate } } + /// + /// Manually performs a single update check against the remote manifest. + /// Raises or based on the result. + /// If an update is already in progress, the call is ignored. + /// + /// A task that represents the asynchronous check operation. + /// The updater has been disposed. + public async Task CheckForUpdateAsync() + { + ThrowIfDisposed(); + await CheckForUpdateInternalAsync(); + } + private async void UpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + await CheckForUpdateInternalAsync(); + } + + private async Task CheckForUpdateInternalAsync() { if (Interlocked.CompareExchange(ref updating, 0, 0) != 0) { diff --git a/README.md b/README.md index 82acafa..a5a3405 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,13 @@ private static async void Updater_UpdateAvailable(string version, string changel } } ``` +### Manually checking for updates +Use `CheckForUpdateAsync()` to trigger a single update check at any time, independently of the timer interval. +`UpdateAvailable` or `NoUpdateAvailable` will be raised as usual when the check completes. +```cs +await updater.CheckForUpdateAsync(); +``` +This is also useful when the `Updater` is created without a timer interval or with `onlyUpdateOnce: true`, giving full control over when checks occur. ### Update process reporting ```cs private static void Updater_ProgressChanged(UpdateStep step, long itemsProcessed, long? totalItems, double? progressPercentage)