Created
March 5, 2015 05:53
-
-
Save sholfen/eb98271c9aa2b3de856b to your computer and use it in GitHub Desktop.
Async Sample
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
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