Created
September 6, 2016 05:03
-
-
Save munron/3cbc654d7367a41ce73a810039b250c8 to your computer and use it in GitHub Desktop.
C# Task 入門 2 async await
This file contains 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.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