Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async event handlers #571

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/NetSparkle/NetSparkle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
<RootNamespace>NetSparkleUpdater</RootNamespace>
<PackageReleaseNotes>See https://github.com/NetSparkleUpdater/NetSparkle/releases for all release information and to file issues/pull requests for this project.</PackageReleaseNotes>
<NoWarn>VSTHRD200, VSTHRD100, VSTHRD002, VSTHRD001</NoWarn>
</PropertyGroup>
<PropertyGroup>
<IncludeSymbols>true</IncludeSymbols>
Expand Down Expand Up @@ -100,6 +101,7 @@
<!--<PackageReference Include="BouncyCastle.Cryptography" Version="2.0.0" /> TODO: 3.0 -->
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="17.9.28" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
</ItemGroup>
Expand Down
8 changes: 6 additions & 2 deletions src/NetSparkle/SparkleUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -686,7 +687,7 @@
// check if any updates are available
try
{
await Task.Factory.StartNew(() =>

Check warning on line 690 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (windows-latest)

Avoid method overloads that assume TaskScheduler.Current. Use an overload that accepts a TaskScheduler and specify TaskScheduler.Default (or any other) explicitly. (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD105.md)

Check warning on line 690 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (windows-latest)

Avoid method overloads that assume TaskScheduler.Current. Use an overload that accepts a TaskScheduler and specify TaskScheduler.Default (or any other) explicitly. (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD105.md)

Check warning on line 690 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (windows-latest)

Avoid method overloads that assume TaskScheduler.Current. Use an overload that accepts a TaskScheduler and specify TaskScheduler.Default (or any other) explicitly. (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD105.md)

Check warning on line 690 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (macos-latest)

Avoid method overloads that assume TaskScheduler.Current. Use an overload that accepts a TaskScheduler and specify TaskScheduler.Default (or any other) explicitly. (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD105.md)

Check warning on line 690 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (macos-latest)

Avoid method overloads that assume TaskScheduler.Current. Use an overload that accepts a TaskScheduler and specify TaskScheduler.Default (or any other) explicitly. (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD105.md)

Check warning on line 690 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (macos-latest)

Avoid method overloads that assume TaskScheduler.Current. Use an overload that accepts a TaskScheduler and specify TaskScheduler.Default (or any other) explicitly. (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD105.md)

Check warning on line 690 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (ubuntu-latest)

Avoid method overloads that assume TaskScheduler.Current. Use an overload that accepts a TaskScheduler and specify TaskScheduler.Default (or any other) explicitly. (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD105.md)

Check warning on line 690 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (ubuntu-latest)

Avoid method overloads that assume TaskScheduler.Current. Use an overload that accepts a TaskScheduler and specify TaskScheduler.Default (or any other) explicitly. (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD105.md)

Check warning on line 690 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (ubuntu-latest)

Avoid method overloads that assume TaskScheduler.Current. Use an overload that accepts a TaskScheduler and specify TaskScheduler.Default (or any other) explicitly. (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD105.md)
{
LogWriter.PrintMessage("About to start downloading the app cast...");
if (AppCastHandler.DownloadAndParse())
Expand Down Expand Up @@ -1824,7 +1825,7 @@
// 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:
Expand Down Expand Up @@ -1911,7 +1912,7 @@
}
else
{
_syncContext.Post(async (state) => await action?.Invoke(), null);

Check warning on line 1915 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (windows-latest)

Avoid using async lambda for a void returning delegate type, because any exceptions not handled by the delegate will crash the process (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD101.md)

Check warning on line 1915 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (windows-latest)

Avoid using async lambda for a void returning delegate type, because any exceptions not handled by the delegate will crash the process (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD101.md)

Check warning on line 1915 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (windows-latest)

Avoid using async lambda for a void returning delegate type, because any exceptions not handled by the delegate will crash the process (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD101.md)

Check warning on line 1915 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (macos-latest)

Avoid using async lambda for a void returning delegate type, because any exceptions not handled by the delegate will crash the process (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD101.md)

Check warning on line 1915 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (macos-latest)

Avoid using async lambda for a void returning delegate type, because any exceptions not handled by the delegate will crash the process (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD101.md)

Check warning on line 1915 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (macos-latest)

Avoid using async lambda for a void returning delegate type, because any exceptions not handled by the delegate will crash the process (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD101.md)

Check warning on line 1915 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (ubuntu-latest)

Avoid using async lambda for a void returning delegate type, because any exceptions not handled by the delegate will crash the process (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD101.md)

Check warning on line 1915 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (ubuntu-latest)

Avoid using async lambda for a void returning delegate type, because any exceptions not handled by the delegate will crash the process (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD101.md)

Check warning on line 1915 in src/NetSparkle/SparkleUpdater.cs

View workflow job for this annotation

GitHub Actions / Unit testing (ubuntu-latest)

Avoid using async lambda for a void returning delegate type, because any exceptions not handled by the delegate will crash the process (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD101.md)
}
}

Expand Down Expand Up @@ -2048,7 +2049,10 @@
LatestVersion = updates[0],
AppCastItems = updates
};
UpdateDetected?.Invoke(this, ev);

if (UpdateDetected != null)
await UpdateDetected.InvokeAsync(this, ev);

if (_cancelToken.IsCancellationRequested)
{
break;
Expand Down
11 changes: 7 additions & 4 deletions src/NetSparkle/SparkleUpdaterEvents.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -13,6 +13,7 @@ public partial class SparkleUpdater : IDisposable
/// This event will be raised when an update check is about to be started
/// </summary>
public event LoopStartedOperation LoopStarted;

/// <summary>
/// This event will be raised when an update check has finished
/// </summary>
Expand All @@ -22,11 +23,13 @@ public partial class SparkleUpdater : IDisposable
/// Called when update check has just begun
/// </summary>
public event UpdateCheckStarted UpdateCheckStarted;

/// <summary>
/// This event can be used to override the standard user interface
/// process when an update is detected
/// </summary>
public event UpdateDetected UpdateDetected;
public event AsyncEventHandler<UpdateDetectedEventArgs> UpdateDetected;

/// <summary>
/// Called when update check is all done. <see cref="UpdateDetected"/> may have been
/// called between the start and end of the update check.
Expand Down
Loading