Reputation: 2532
I'm totally green with TPL and want to execute an async method in a console application.
My code:
static void Main()
{
Task<string> t = MainAsync();
t.Wait();
Console.ReadLine();
}
static async Task<string> MainAsync()
{
var result = await (new Task<string>(() => { return "Test"; }));
return result;
}
This task runs forever. Why? What am I missing?
Upvotes: 2
Views: 1252
Reputation: 15364
You don't start your task. This is why Wait
doesn't return. Try
var result = await Task.Run<string>(() => { return "Test"; });
Upvotes: 8