NetSparkleUpdater / NetSparkle

NetSparkle is a C# cross-platform software update framework for .NET developers compatible with .NET 4.6.2/.NET 6+, WinForms, WPF, and Avalonia; uses Ed25519 or DSA signatures! View basic usage here in the README or visit our website for code docs.
https://netsparkleupdater.github.io/NetSparkle/
MIT License
585 stars 81 forks source link

Async event handlers #571

Open sdijoseph opened 3 months ago

sdijoseph commented 3 months ago

I had a use case for the UpdateDetected event where I wanted to call asynchronous code inside the event handler. With the current code, it doesn't seem possible to call async code within the handler and actually ensure that code finishes executing before SparkleUpdater continues it's normal flow.

I'm proposing in this PR to make SparkleUpdater's events AsyncEventHandlers, so the completion of all handler for each event can be awaited inside the SparkleUpdater code using InvokeAsync. I'm using the implementation provided by the Microsoft.VisualStudio.Threading package-system-object-0)). (This package adds a ton of warnings related to async code, so I set the NoWarn flag for them)

This is a breaking change, as current handlers will now have to return "Task.CompletedTask" since the handlers are expected to return Task instead of void. I'm submitting this as a draft PR with only UpdateDetected converted to AsyncEventHandler. If you agree with this approach, I can convert the remaining events as well.

Deadpikle commented 3 months ago

Hey, thank you for sending in this PR. I'm holding off on it for now until I figure out what to do about the various threading issues in this lib, since they might require more extensive changes. I really appreciate it :-) Not closing for now until I have time to look at it more closely. Thanks!