====== 実行結果 ======
$ dotnet run
This is MethodSample - a.
This is Main method - a.
This is MethodSample - b.
This is Main method - b.
====== ソース ======
using System;
using System.Threading.Tasks;
using System.Threading;
namespace console
{
class Program
{
static void Main(string[] args)
{
AsyncAwaitSample Sample = new AsyncAwaitSample();
Sample.MethodSample();
Console.WriteLine("This is Main method - a.");
Thread.Sleep( 3000 );
Console.WriteLine("This is Main method - b.");
}
}
public class AsyncAwaitSample
{
// This method is asyncronized method.
// so, after "await" return to Main method immediately.
public async void MethodSample()
{
Console.WriteLine("This is MethodSample - a.");
await Task.Run( () => {
Thread.Sleep( 2000 );
} );
Console.WriteLine("This is MethodSample - b.");
}
}
}