diff --git a/src/NetSparkle.Samples.HandleEventsYourself/MainWindow.xaml.cs b/src/NetSparkle.Samples.HandleEventsYourself/MainWindow.xaml.cs index d53a97b5..4e578d35 100644 --- a/src/NetSparkle.Samples.HandleEventsYourself/MainWindow.xaml.cs +++ b/src/NetSparkle.Samples.HandleEventsYourself/MainWindow.xaml.cs @@ -169,9 +169,10 @@ private async void UpdateAutomaticallyButton_Click(object sender, RoutedEventArg await _sparkle.CheckForUpdatesQuietly(); } - private void _sparkle_FullUpdate_UpdateDetected(object sender, Events.UpdateDetectedEventArgs e) + private Task _sparkle_FullUpdate_UpdateDetected(object sender, Events.UpdateDetectedEventArgs e) { RunFullUpdateUpdateStatusLabel.Text = "Found update..."; + return Task.CompletedTask; } private void _sparkle_FullUpdate_StartedDownloading(AppCastItem item, string path) diff --git a/src/NetSparkle/NetSparkle.csproj b/src/NetSparkle/NetSparkle.csproj index 7966853b..127a0ba4 100644 --- a/src/NetSparkle/NetSparkle.csproj +++ b/src/NetSparkle/NetSparkle.csproj @@ -19,6 +19,7 @@ true NetSparkleUpdater See https://github.com/NetSparkleUpdater/NetSparkle/releases for all release information and to file issues/pull requests for this project. + VSTHRD200, VSTHRD100, VSTHRD002, VSTHRD001 true @@ -100,6 +101,7 @@ + diff --git a/src/NetSparkle/SparkleUpdater.cs b/src/NetSparkle/SparkleUpdater.cs index 22aa6e38..b229af1f 100644 --- a/src/NetSparkle/SparkleUpdater.cs +++ b/src/NetSparkle/SparkleUpdater.cs @@ -19,6 +19,7 @@ using NetSparkleUpdater.AssemblyAccessors; using System.Text; using System.Globalization; +using Microsoft.VisualStudio.Threading; #if (NETSTANDARD || NET6 || NET7 || NET8) using System.Runtime.InteropServices; #endif @@ -1824,7 +1825,7 @@ private async Task CheckForUpdates(bool isUserManuallyCheckingForUpd // handling everything. if (UpdateDetected != null) { - UpdateDetected(this, ev); // event's next action can change, here + await UpdateDetected.InvokeAsync(this, ev); // event's next action can change, here switch (ev.NextAction) { case NextUpdateAction.PerformUpdateUnattended: @@ -2048,7 +2049,10 @@ private async void OnWorkerDoWork(object sender, DoWorkEventArgs e) LatestVersion = updates[0], AppCastItems = updates }; - UpdateDetected?.Invoke(this, ev); + + if (UpdateDetected != null) + await UpdateDetected.InvokeAsync(this, ev); + if (_cancelToken.IsCancellationRequested) { break; diff --git a/src/NetSparkle/SparkleUpdaterEvents.cs b/src/NetSparkle/SparkleUpdaterEvents.cs index b72a10b6..ff207d53 100644 --- a/src/NetSparkle/SparkleUpdaterEvents.cs +++ b/src/NetSparkle/SparkleUpdaterEvents.cs @@ -1,9 +1,9 @@ using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Net; -using System.Text; using System.Diagnostics; +using System.Threading.Tasks; +using Microsoft.VisualStudio.Threading; +using NetSparkleUpdater.Events; namespace NetSparkleUpdater { @@ -13,6 +13,7 @@ public partial class SparkleUpdater : IDisposable /// This event will be raised when an update check is about to be started /// public event LoopStartedOperation LoopStarted; + /// /// This event will be raised when an update check has finished /// @@ -22,11 +23,13 @@ public partial class SparkleUpdater : IDisposable /// Called when update check has just begun /// public event UpdateCheckStarted UpdateCheckStarted; + /// /// This event can be used to override the standard user interface /// process when an update is detected /// - public event UpdateDetected UpdateDetected; + public event AsyncEventHandler UpdateDetected; + /// /// Called when update check is all done. may have been /// called between the start and end of the update check.