Posts

Showing posts from October, 2015

Amazing Things You Can Do With Azure Storage Queues

Image
Load Balancing and Workload distribution Queues can be used to organise the distribution of a workload across multiple processors. A common technique is to post messages to a queue which are a key to a task which needs to be performed, and have multiple worker processes pick these tasks from the queue to perform in parallel. This can be combined with other storage mechanisms to perform complex tasks. Say you were trying to render an animation. The queue could be loaded with keys, which point to an entity in Table storage. This entity could contain the Url of an image stored in blob storage. A worker process would pick up the message from the queue, reference the entity from the table and download the image from blob storage. It could then perform compute intensive tasks on the image while other worker processes picked up other images. In this way, cloud storage can be used to augment worker roles and perform powerful parallel operations. Asynchronous Processing and Temporal

Calling Long Running Methods Asynchronously

Image
When you are able to call an async method, do it using async and await or by making your method return a Task: p ublic async Task < string > RequestData ( Uri uri ) {     WebClient webClient = new WebClient ();     return await webClient.DownloadStringTaskAsync ( uri ); } // Rely on underlying Tasks whenever possible. public Task < string > RequestDataAsync ( Uri uri ) {     WebClient webClient = new WebClient ();     return webClient.DownloadStringTaskAsync ( uri ); } // Rely on underlying Tasks whenever possible. Dealing with synchronous calls When the method you are calling is not asynchronous, wrap the method in a task delegate:   public Task < string > RequestDataAsync ( Uri uri ) {     return Task .Run < string >(         () =>         {             WebClient webClient = new WebClient ();             return webClient.DownloadString ( uri );         }); } // Create Tasks when you have no