This file contains hidden or 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
var stopwatch = Stopwatch.StartNew(); | |
var t1 = Task.Run(() => | |
{ | |
Thread.Sleep(1000); | |
Console.WriteLine(stopwatch.Elapsed); | |
}); | |
var t2 = Task.Run(() => | |
{ | |
Thread.Sleep(1000); | |
Console.WriteLine(stopwatch.Elapsed); |
This file contains hidden or 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
var stopwatch = Stopwatch.StartNew(); | |
await Task.Run(() => | |
{ | |
Thread.Sleep(1000); | |
Console.WriteLine(stopwatch.Elapsed); | |
}); | |
await Task.Run(() => | |
{ | |
Thread.Sleep(1000); | |
Console.WriteLine(stopwatch.Elapsed); |
This file contains hidden or 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
int index = 0; | |
using (WebResponse response = await webRequest.GetResponseAsync()) | |
{ | |
byte[] inputBuffer = new byte[response.ContentLength]; | |
Stream stream = response.GetResponseStream(); | |
int bytesRead; | |
do | |
{ |
This file contains hidden or 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
public static Task<String> CalculatePiAsync(int digits) | |
{ | |
return Task.Factory.StartNew(() => CalculatePi(digits)); | |
} | |
public static string CalculatePi(int digits) | |
{ | |
string result = ""; | |
// TODO:... | |
return result; |
This file contains hidden or 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
var pi = await Program.CalculatePiAsync(14); | |
Assert.AreEqual("3.14159265358979323846", pi); |
This file contains hidden or 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
var pi = Program.CalculatePi(20); | |
Assert.AreEqual("3.14159265358979323846", pi); |
This file contains hidden or 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
[TestMethod] | |
public async void TestPiAsync() | |
{ | |
var pi = await Program.CalculatePiAsync(15); | |
Assert.AreEqual("3.14159265358979323846", pi); | |
} |
This file contains hidden or 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
[TestMethod] | |
public async Task TestPiAsync() | |
{ | |
var pi = await Program.CalculatePiAsync(15); | |
Assert.AreEqual("3.14159265358979323846", pi); | |
} |
This file contains hidden or 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
public async Task Method() | |
{ | |
await Task.Factory.StartNew(() => Console.WriteLine("I'm asynchronous!")); | |
} |
This file contains hidden or 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
await Method(); |