Skip to content

Instantly share code, notes, and snippets.

@sholfen
Created March 5, 2015 05:53
Show Gist options
  • Save sholfen/eb98271c9aa2b3de856b to your computer and use it in GitHub Desktop.
Save sholfen/eb98271c9aa2b3de856b to your computer and use it in GitHub Desktop.
Async Sample
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsyncConsoleApplication
{
class Program
{
static void Main(string[] args)
{
A1Class a1 = new A1Class();
a1.Method1();
Console.ReadLine();
}
}
public class A1Class
{
public void Method1()
{
Console.WriteLine("Method1 Start");
this.Method2();
Console.WriteLine("Method1 End");
}
public async void Method2()
{
Console.WriteLine("Method2 Start");
await Task.Run(
() => {
int i = 0;
while (i < 10) {
++i;
Console.WriteLine(i.ToString());
}
});
Console.WriteLine("Method2 End");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment