Modifier: async / await

Used to mark a method as being asynchronous and to await results from the asynchronous processing. Available from .NET 4.5 (C# 5).

Example:

using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Windows;

namespace Examples
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        /// <summary>
        /// Standard WPF initialization
        /// </summary>
        public MainWindow()
        {
            Console.WriteLine("Initializing...");
            InitializeComponent();
            Console.WriteLine("Finished Initializing.");
        }

        /// <summary>
        /// Async download webpage
        /// </summary>
        /// <returns></returns>
        async Task<int> DownloadWeb()
        {
            Console.WriteLine("Started Async.");
            HttpClient client = new HttpClient();
            Task<string> getStringTask = client.GetStringAsync("http://msdn.microsoft.com");

            Console.WriteLine("Starting await.");
            string urlContents = await getStringTask;
            Console.WriteLine("Finished await.");
            return urlContents.Length;
        }

        /// <summary>
        /// Handle a button press as an async task
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            int length = await DownloadWeb();
            Console.WriteLine("Got Result: " + length);
        }
    }
}

XAML

<Window x:Class="Examples.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Examples"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Button Content="Button" HorizontalAlignment="Left" Margin="305,134,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
    </Grid>
</Window>