Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3317480
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:35:33+00:00 2026-05-17T22:35:33+00:00

Microsoft announced the Visual Studio Async CTP today (October 28, 2010) that introduces the

  • 0

Microsoft announced the Visual Studio Async CTP today (October 28, 2010) that introduces the async and await keywords into C#/VB for asynchronous method execution.

First I thought that the compiler translates the keywords into the creation of a thread but according to the white paper and Anders Hejlsberg’s PDC presentation (at 31:00) the asynchronous operation happens completely on the main thread.

How can I have an operation executed in parallel on the same thread? How is it technically possible and to what is the feature actually translated in IL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:35:33+00:00Added an answer on May 17, 2026 at 10:35 pm

    It works similarly to the yield return keyword in C# 2.0.

    An asynchronous method is not actually an ordinary sequential method. It is compiled into a state machine (an object) with some state (local variables are turned into fields of the object). Each block of code between two uses of await is one “step” of the state machine.

    This means that when the method starts, it just runs the first step and then the state machine returns and schedules some work to be done – when the work is done, it will run the next step of the state machine. For example this code:

    async Task Demo() { 
      var v1 = foo();
      var v2 = await bar();
      more(v1, v2);
    }
    

    Would be translated to something like:

    class _Demo {
      int _v1, _v2;
      int _state = 0; 
      Task<int> _await1;
      public void Step() {
        switch(this._state) {
        case 0: 
          this._v1 = foo();
          this._await1 = bar();
          // When the async operation completes, it will call this method
          this._state = 1;
          op.SetContinuation(Step);
        case 1:
          this._v2 = this._await1.Result; // Get the result of the operation
          more(this._v1, this._v2);
      }
    }
    

    The important part is that it just uses the SetContinuation method to specify that when the operation completes, it should call the Step method again (and the method knows that it should run the second bit of the original code using the _state field). You can easily imagine that the SetContinuation would be something like btn.Click += Step, which would run completely on a single thread.

    The asynchronous programming model in C# is very close to F# asynchronous workflows (in fact, it is essentially the same thing, aside from some technical details), and writing reactive single-threaded GUI applications using async is quite an interesting area – at least I think so – see for example this article (maybe I should write a C# version now :-)).

    The translation is similar to iterators (and yield return) and in fact, it was possible to use iterators to implement asynchronous programming in C# earlier. I wrote an article about that a while ago – and I think it can still give you some insight on how the translation works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Microsoft recently announced that the Javascript/HTML DOM library jQuery will be integrated into the
Microsoft recently announced that they were endorsing jQuery as an officially supported JavaScript library.
Microsoft Visual Studio (2005 and 2008) seems to have fun shuffling the Project IDs
Microsoft released the source for Oxite , their blogging engine that's intended to help
Microsoft recently announced their Facebook SDK. http://msdn.microsoft.com/en-us/windows/ee388574.aspx Has anyone tried using it with ASP.NET
I have an idea for the newly announced Microsoft Vine, and I was wondering
Microsoft's reference doesn't say anything, but it seems that currentle everyone uses three dots
Microsoft SQL Server Profiler is a graphical user interface to SQL Trace for monitoring
Microsoft's new Windows Live Application Based Storage API is a RESTful API. More info
Microsoft Access is a slick way to access data in a MS SQL Server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.