Asynchronous programming is used to avoid unnecessary lags in performance. For example, in a synchronous application, if one particular part of a web page takes a long time to load the whole application stalls. However, asynchronously, this can be avoided by allowing other parts of the web page to render whilst the slow part is being resourced. Since C# 5, this has been easy to do and is shown below. In the demo used here, a simple console application is used. The Main method (not shown) simply calls the Run method as can be seen below. Note that the Run method has an async modifier which allows the await operator to be used within it. Firstly, the GetRandomNumberTask method is called - this is what will be causing the lag in performance. However, crucially the IndependentMethod method runs before the GetRandomNumberTask has completed. In this example, an artificial delay of 3 seconds is used to simulate a genuine server lag, afterwards a ran...
My name is Ben and I am a software developer from Sussex, England. The purpose of this blog is to keep a record of technologies I utilise throughout my career as a software developer. I believe that not only will this further cement my understanding of these technologies, but also serve as a useful personal resource for future work.