What's new with async support for WinForms event handlers?
See original GitHub issueI’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:
- Created 2 years ago
- Reactions:2
- Comments:9 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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!
Well, depending events can be problematic, since
async voidare fire and forgets. So, if you have for example aProcessingand aProcessedevent, whereProcessingis supposed to be blocked on the consumer-side, you might be ending up with firing both in succession, sinceProcessingwould 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.