I am using the Microsoft.Bcl.Async nuget package to use Async/Await (My target is .NET 4, rather than 4.5)
I am new to Async/Await. My problem is described in the following code sample. Why is the highlighted line not called?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsyncTest
{
class Program
{
static void Main(string[] args)
{
Run();
Console.WriteLine("Got the value");
Console.ReadKey();
}
public static async void Run()
{
Console.WriteLine("Testing Async...");
var val = await AsyncMethod();
// HIGHLIGHTED LINE. WHY IS THIS LINE NOT CALLED?
Console.WriteLine("And the value is... {0}", val);
}
public static Task<long> AsyncMethod()
{
long myVal = 1;
for (long l = 0; l < 100000; l++)
{
myVal++;
Console.WriteLine("l = {0}", l);
}
return new Task<long>(() => myVal);
}
}
}