Saturday, March 10, 2012

the async keyword (for asynchronous threading concerns) is coming in C# 5.0

I saw Headspring's Ryan Vice speak on "Windows 8 Metro Applications with XAML and C#" today at the Dallas Day of .NET convention. He demoed code in the beta for Visual Studio 11 which it seems comes with C# 5.0. The async keyword is coming with C# 5.0. He is some of Ryan's code which I do not yet really understand:

async public Task <IEnumerable<ToDo>> GetAsync() {

 
 

More:

await _repository.SaveAsync();

 
 

2 comments:

  1. Thanks for coming out.

    That code uses the async key word to indicate to the complier that the method will be making async calls using the await key word. The await key word then indicates to the complier that the method that follows should be called asynchronously. The compiler will then break apart the method into two methods (1) everthing from start till await (2) everything after the await. The compiler will then structure the code so that the method following await will be called asynchronously and then will use (2) as a callback.

    If you have any questions are concerns don't hesitate to email me.

    Ryan

    ReplyDelete
  2. Thank you Ryan! Your comments are very informative and alleviate a bunch of bad assumptions I was making about async and await.

    ReplyDelete