Skip to content

Instantly share code, notes, and snippets.

@munron
Created September 6, 2016 05:03
Show Gist options
  • Save munron/3cbc654d7367a41ce73a810039b250c8 to your computer and use it in GitHub Desktop.
Save munron/3cbc654d7367a41ce73a810039b250c8 to your computer and use it in GitHub Desktop.
C# Task 入門 2 async await
using System;
using System.Threading.Tasks;
using System.Threading;
namespace ConsoleApplication13
{
class Program
{
static void Main()
{
var task = DoSomethingAsync();
//--- この間、何か別の処理をしたりすると良い
Console.WriteLine("何か別の処理");
task.Wait();
Console.WriteLine("お終い!!");
Console.ReadKey();
}
//mainにasyncは無理だからinternalかませる!!
internal static async Task DoSomethingAsync()
{
await Task.Run(() => Thread.Sleep(3000));
Console.WriteLine("何か非同期で実行しました");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment