Implement Async/Await in Webform IN A PRACTICAL WAY
I really like async/await, but I can't say I am impressed with the way it has been implemented in webforms. If I understand correctly RegisterAsyncTask doesn't give you any control on when the code is executed in the execution pipeline (and not even available within master pages!). I am sure there must be a simpler way. Why use events in the first place? Webforms are really not forms, and all these methods could really be functions returning a task, why do they need to be voids returning event handlers? Why not let users define Task functions that will be called in a similar order as the current event handlers?
Looks like because of the shift to MVC, microsoft is not eating its own dog food anymore with webforms and providing a half-baked implementation of Async/Await.
Thank you for your feedback. Please take a look at Model Binding which was introduced in .NET 4.5 and we also added support for Async Model Binding in .NET 4.6
And one thing that makes it really annoying (and dangerous, i.e. bug prone) to use is that because the tasks are executed quite late in the event cycle, they get executed much later than some events that would normally rely on them.
Typical example is loading some data from a database in Page_Load, then using them on Click events. But data loading is typically something that must be done Async. And therefore the Click event must themselves register an async task in order for the code to be executed after the Page_Load task, even though they are doing nothing Async themselves (using Task.Delay(0) for instance).
My opinion is that the way Async/Await has been designed to work with events is disastrous (in Webform or anywhere else). Asyn/Await is a fabulous innovation but the integration with events should have required a redesign of even handling to accommodate task-returning functions handlers. I have the feeling some shortcuts have been made that are leading to lots of unnecessary complications for users to make it work.
I should add that having to put the async code in RegisterAsyncTask is exactly like having to use call back functions, forcing the logic to be split between what is async and what is not. It defeats the whole purpose of async/await in the first place.