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

Asynchronous Anonymous Functions

Anonymous methods using the delegate keyword or using lambda expression notification can also be marked with the async modifier. A good example of the use of this is when calling Task.Run, to start work on the task pool. A couple of overloads of this method are shown here:

public static Task Run(Action action);public static Task<TResult> Run<TResult>(Func<Task<TResult>> function);public static Task Run(Func<Task> function);public static Task<TResult> Run<TResult>(Func<TResult> function);

Additional overloads provide a CancellationToken parameter. Notice how the function and action parameter delegate types all conform to valid asynchronous method signatures. In particular, the Action ...

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