How Async and Await Work Behind the Scenes
Behind the scenes of the ease of the Async
pattern, the compiler does incredible work to make the magic possible. When you make an asynchronous call by using Await
, that invocation starts a new instance of the Task
class. As you know from Chapter 41, one thread can contain multiple Task
instances. So you might have the asynchronous operation running in the same thread but on a new Task
. Internally, it’s as if the compiler could split an asynchronous method in two parts, a method and its callback. If you consider the QueryVideosAsync
shown previously, you could imagine a method defined until the invocation of Await
. The next part of the method is moved into a callback that is invoked after the awaited ...
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.