Last active
December 24, 2015 23:39
-
-
Save robertiagar/6882132 to your computer and use it in GitHub Desktop.
async await demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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