Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Created June 4, 2012 13:18
Show Gist options
  • Save masaru-b-cl/2868318 to your computer and use it in GitHub Desktop.
Save masaru-b-cl/2868318 to your computer and use it in GitHub Desktop.
async/awaitってこうじゃないの?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DoSomething();
}
private static async void DoSomething()
{
var s = await AsyncMethod("Sho");
Console.WriteLine(s);
}
private static Task<string> AsyncMethod(string name)
{
return new Task<string>(() =>
{
Thread.Sleep(3000);
return "Hello world, " + name;
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment