dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
6.84k stars 1.13k forks source link

please add Task event to controls #9045

Open ali50m opened 3 weeks ago

ali50m commented 3 weeks ago

It's 2024 now... Please don't let the button.click event to handle async/await task with async void signature.

miloush commented 3 weeks ago

This would be a significant breaking change on several levels, existing code would no longer compile, the events would have different signature and the behavior would change (e.g. exception handling). The only way to solve this in backwards compatible way that comes to my mind is to duplicate all the events with their async counterparts, e.g. have ClickAsync etc. Even then, you might need to deal with events being fired before other events finished.

I don't say it often, but I suggest to see how this is resolved in Winforms first. Relevant discussion: https://github.com/dotnet/winforms/issues/6478

ali50m commented 3 weeks ago

@miloush thanks for the redirection to winform similar issues. Is there a already WPF progress issue for tracking this? I think WPF guys also want the async control event.

miloush commented 3 weeks ago

It is not really a WPF specific problem, but no, I think this is the first issue in this repo that can be used to track it.

Would you mind sharing why async void event handlers don't work for you, or what kind of scenarios are you currently unable to realize?

ali50m commented 3 weeks ago

No, I am doing WPF mainly with CommunityToolkit.Mvvm package, which can call the async task through AsyncRelayCommand.

I am doing some research with Blazor these days. I think the OnInitialized/OnInitializedAsync like method is more convenient than WPF when invoking event handler in code behind.