How I'll access this Task <String> return value in C#?

Viewed 1294

I am following this blogpost by @StephenHaunts here https://stephenhaunts.com/2014/10/10/simple-async-await-example-for-asynchronous-programming/#comments

What is the purpose of last return statement in the code, inside LongRunningOperation.

private static async Task<string> LongRunningOperation()
{
     int counter;    
     for (counter = 0; counter < 50000; counter++)
     {
         Console.WriteLine(counter);
     }    
     return "Counter = " + counter;
}

Now what I know is:

  1. As I am calling this LongrunningOperation inside Task.Run, it should return whatever this awaited method is returning by default. Then Why it is not doing that.

  2. If I use Task.Result property then It'll run behave synchronously and block calling thread, which is not recommended.

What I want to ask is:

  1. How I'll get this returned value printed at calling spot?

  2. And why @Stephen have written that statement when there is no need of it?

Thanks in advance.

2 Answers
Related