More on Async Functions

In my last post I showed .Net 1.1 and .NET 2.0 code that performed some asychronous operations.  I then showed the new syntax with “async” and “await” that did the same thing. But, I didn’t detail what’s really going on in the new syntax. If you want to know more about the details of what’s going on, read on.  If you just trust me about the previous code, you don’t have to read on 🙂 When the Click handler is executed it basically executes everything up to the first await and returns.  This allows the UI to be responsive.  The … Continue reading More on Async Functions

A New Asynchronicity Awaits You

The languages team at Microsoft have just announced that both VB and C# are giving first-class citizenship to asynchronous operations. At long last we can cleanly program for asynchronous operations without cluttering up the code with imperative artefacts relating to how the asynchronous operation is being performed. Let’s have a quick look at how we had you might perform an asynchronous operation in .NET 1.x: byte[] readbuffer = new byte[1024]; public void Button1_Click() { WebRequest webRequest = WebRequest.Create(“”); webRequest.BeginGetResponse(new AsyncCallback(BeginGetResponseCallback), webRequest); } private void BeginGetResponseCallback(IAsyncResult asyncResult) { WebRequest webRequest = (WebRequest)asyncResult.AsyncState; WebResponse webResponse = webRequest.EndGetResponse(asyncResult); Stream stream = webResponse.GetResponseStream(); stream.BeginRead(readbuffer, … Continue reading A New Asynchronicity Awaits You