question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What's new with async support for WinForms event handlers?

See original GitHub issue

I’m sure I’m not the first to ask this but is there anything new with regards to WinForms event handlers implementing async?

Basically, since everything is basically done in event handlers with WinForms, the question is can I use async/await at all?

Looks like the old workaround is to return void instead of Task. But I know this can cause problems.

I know the WinForms engine was recently built for .NET 5.0/6.0. Was any thought given to this?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
KlausLoeffelmanncommented, Jan 9, 2022

We have planned this for the .NET 7 timeframe, but we also need to complete some urgent new Designer functionality, so we may reprioritize or not tackle all of those. As always: Help for from the community is highly appriciated!

https://github.com/dotnet/winforms/issues/4631 https://github.com/dotnet/winforms/issues/5917 https://github.com/dotnet/winforms/issues/5918

If you have other things in mind, you’d find important, please file an issue!

0reactions
KlausLoeffelmanncommented, Aug 17, 2023

Well, depending events can be problematic, since async void are fire and forgets. So, if you have for example a Processing and a Processed event, where Processing is supposed to be blocked on the consumer-side, you might be ending up with firing both in succession, since Processing would not be (a)waiting for the consumer-side to be finished, since it is a fire and forget. So, invoking that event should be done asynchronously and awaited.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Winforms call to async method hangs up program
Event handlers are the only place you are allowed to do async void . The other option is tell Task.Delay it does not...
Read more >
Using Async, Await, and Task to keep the WinForms UI ...
Using the async/await pattern in WinForms is an easy win, helping prevent one of the most annoying user experiences - a frozen UI....
Read more >
How to: Implement a Client of the Event-based ...
The following code example demonstrates how to use a component that adheres to the Event-based Asynchronous Pattern Overview.
Read more >
Async and Async Void Event Handling in WPF - Rick Strahl
Event Handlers that await exit before the await method completes. The first issue is that the event immediately completes execution when it hits...
Read more >
Use of Async/Await for EventHandlers
In doing async (s, e) => await SomeMethodAsync() I am merely setting up an event handler equivalent to private async void ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found