Skip to content

Instantly share code, notes, and snippets.

@robertiagar
Last active December 24, 2015 23:39
Show Gist options
  • Save robertiagar/6882132 to your computer and use it in GitHub Desktop.
Save robertiagar/6882132 to your computer and use it in GitHub Desktop.
async await demo
class Test
{
public static async void Test()
{
var i1 = await DoWorkAsync(); //waits for the result, non-ui blocking.
var i2 = DoWork(); //blocks ui until gets result.
}
public static async Task<int> DoWorkAsync()
{
//simulate long running operation.
await Task.Delay(1000);
return 5;
}
public static int DoWork()
{
Thread.Sleep(1000);
return 5;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment