Damian Edwards dal team ASP.NET ha dato questa risposta:
Async void event handlers in web forms are only supported on certain events, as you've found, but are really only intended for simplistic tasks. We recommend using PageAsyncTask for any async work of any real complexity.
Levi Broderick dal team ASP.NET ha dato questa risposta:
Async events in web applications are inherently strange beasts. Async void is meant for a fire and forget programming model. This works in Windows UI applications since the application sticks around until the OS kills it, so whenever the async callback runs there is guaranteed to be a UI thread that it can interact with. In web applications, this model falls apart since requests are by definition transient. If the async callback happens to run after the request has finished, there is no guarantee that the data structures the callback needs to interact with are still in a good state. Thus why fire and forget (and async void) is inherently a bad idea in web applications.
That said, we do crazy gymnastics to try to make very simple things like Page_Load work, but the code to support this is extremely complicated and not well-tested for anything beyond basic scenarios. So if you need reliability I’d stick with RegisterAsyncTask.
Quindi penso che la risposta alla mia domanda è: "Questa è la domanda sbagliata."
La domanda giusta sarebbe "Come dovrei essere asincrono nella mia applicazione Web Form ASP.NET?" E la risposta è di inserire questo frammento all'interno del vostro file code-behind aspx:
this.RegisterAsyncTask(new PageAsyncTask(async cancellationToken => {
var result = await SomeOperationAsync(cancellationToken);
// do something with result.
}));
Questo stesso trucco funziona all'interno di controlli personalizzati ASP.NET, basta usare this.Page.RegisterAsyncTask
invece.
fonte
2013-02-09 23:39:31
Questo articolo può essere d'aiuto: http://msdn.microsoft.com/en-us/magazine/gg598924.aspx – Aristos
Grazie. Sicuramente una buona lettura, anche se non risponde alla mia domanda. –
Questo spiega anche un po ', e dà molto più codice di esempio di quello msdn, ma continua a non rispondere alla tua domanda:/ http://www.asp.net/web-forms/tutorials/aspnet-45/ using-asynchronous-methods-in-aspnet-45 – mirichan