jay's old blog

this blog will be deleted soon - please visit my new blog - https://thesanguinetechtrainer.com

Async and Await Revisited - Update 1

I have already written about async, here. yet, thought I will just revisit here.

The thing is about async and await is all about improving responsiveness. What is responsiveness though? In different context, it takes on different meanings. In a website, the ability to move content around to suit the screen size is responsiveness. You see this a lot in mobile websites which also look equally good on desktop. In a application though, responsiveness comes down to the ability to keep the user engaged when stuff is happening in the background.

A simple everyday application activity is waiting for a photo to load. There would be a photo area, which will be surrounded by the usual application buttons and options. While the photo loads, the rest of the application should still be usable. Perhaps a loading screen with a percentage to show what is happening. Stuff like this is what async and await is all about. It is about making sure that the thread that manages the user interface is able to isolate itself from other stuff such as data queries and processing of data which is happening in the background.

This is the whole point of writing asynchronous code. keeping things from freezing or becoming unresponsive when stuff takes longer than expected.

To this effect, c sharp provides the async and await keywords. These keywords allow a particular method to be marked for the benefit of the compiler, indicating that stuff that follows will be asynchronous. Then, the compiler can go ahead create the necessary task related code. This is the key stuff about async and await. It takes the load off the developer from having to write actual asynchronous code, reducing errors in the process. This also means, all that stuff you know from reading about tasks and threads will come in handy here as well.

As always, find the code sample for this entry at my repo.

Follow me on twitter, facebook and instagram for more updates. Thanks!
Comments are closed