Asynchronous functions make asynchronous programming similar to synchronous programming. You can read my previous post on C# 5.0 features. Normal methods can written as asynchronous as shown below

   1: async Task Demo()

   2: {

   3: await Task.Delay(10000);

   4: Console.WriteLine("Hello World!!");

   5: }

You can call the method as await Demo();

Lambda Expressions and anonymous methods can be preceded by the async word.

   1: Func<Task> Ldemo = async () =>

   2:  { 

   3:    await Task.Delay(10000); 

   4:    Console.WriteLine ("Hello World!!");

   5:  };


You can call the method as await Ldemo();

Asynchronous Lambda expressions can also be used in attaching event handlers:

   1: btnOK.Click +=  async (sender, args) => {await Task.Delay(10000);btnOK.text = "Demo";};

Asynchronous Lambda expressions can return Task<TResult>:
   1: Func<Task<int>> Demo = async () =>

   2: {

   3:   await Task.Delay(10000);

   4:   return 12345;

   5: };

Share this post :


One response to “Asynchronous Lambda Expressions in C#5”

  1. Asynchronous Programming Avatar

    Thank you for providing such information. This is very generous of you providing such vital Information which is

    very informative.

Leave a Reply

Your email address will not be published. Required fields are marked *