O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Yielding Control

Now that you know how custom awaiters work, and how they interact with the compiler-generated code, let’s take a look at one more atypical awaiter that ships with the .NET Framework itself. On the Task class, you can find a static method called Yield, defined as follows:

public static YieldAwaitable Yield();

As the name of the return type implies, the result of calling Yield can be awaited. The effect of doing this is pausing the current asynchronous method, effectively yielding control and allowing for other work to be run before continuing the current method’s execution. Internally, this is simply accomplished by a custom awaiter whose IsCompleted property always returns false. Upon the rendezvous of the compiler-generated ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required