Skip to content

Instantly share code, notes, and snippets.

View peteraritchie's full-sized avatar
😖

Peter Ritchie peteraritchie

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