TechBubbles Microsoft Technology BLOG

Asynchronous Lambda Expressions in C#5

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 :

About the author

Kalyan Bandarupalli

My name is kalyan, I am a software architect and builds the applications using Microsoft .NET technologies. Here I am trying to share what I feel and what I think with whoever comes along wandering to Internet home of mine.I hope that this page and its contents will speak for me and that is the reason I am not going to say anything specially about my self here.

1 Comment

By Kalyan Bandarupalli
TechBubbles Microsoft Technology BLOG

Follow me


Tag Cloud