The Modern Way: The Async Pattern

Visual Basic 2012 introduced a new pattern that solves some problems related to threading and enables you to write better and cleaner code. It does this with two keywords: Async and Await. Async is a modifier you use to mark methods that run asynchronous operations. Await is an operator that gets a placeholder for the result of an asynchronous operation and waits for the result, which will be sent back at a later time while other operations are executed. This enables you to keep the caller thread responsive. For a first understanding of how this pattern works, let’s take a look at the following function that downloads the content of a website as a string, returning the result as an XDocument that can be manipulated ...

Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.