Show TOC

Windows ApplicationsLocate this document in the navigation structure

Develop an OData online application.

C# and Visual Basic allow you to asynchronously program without the need of callbacks. Asynchronous methods are easier to write:
  • async makes your method asynchronous
  • await makes the rest of your method a callback as this example illustrates:
    private async void button1_Click(object sender, EventArgs e) 
       // Call the method that runs asynchronously. 
       string result = await WaitAsynchronouslyAsync(); 
       result += await AnotherWaitAsynchronouslyAsync(); 
       // Display the result. 
       textBox1.Text += result; 
In C#:
  1. The async keyword in the method signature informs the compiler that the method is asynchronous.
  2. When calling the asynchronous method, use the await keyword.
  3. The compiler immediately returns control to the caller.
  4. When the asynchronous method completes, the compiler starts execution from where it left off.
  5. Since the rest of the method runs in the main UI thread, you can update UI controls from within the method itself.