We recommend using PageAsyncTask for any async work of any real complexity. Damian Edwards from the ASP.NET team says:Īsync void event handlers in web forms are only supported on certain events, as you've found, but are really only intended for simplistic tasks. However, Page_Load is a page lifecycle event, and it's a void event handler. Intuitively you may want to make these async by marking the public void Page_Load with async and then awaiting three tasks. Var temperature = (clienttemperature) Įach of this three calls takes about a second, so the total type is 3 seconds. Var clientlocation = Client.DownloadString("api/location") Var clienttemperature = Client.DownloadString("api/temperature") Var clientcontacts = Client.DownloadString("api/contacts") Add up the duration of each Task: public void Page_Load(object sender, EventArgs e) You can do those things in order, synchronously, as is typical. Perhaps you're loading something from disk, calling a web service, and calling a database. Often we'll find ourselves doing three or four things on one page, loading stuff from a number of places. ![]() NET programmers know about Asynchronous Programming is wrong" and I learned a lot. First, I encourage you to listen to episode 327 of the Hanselminutes podcast.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |