Trying to pass function instead lambda expression and finally mixed up why line:
int t2 = await Task.Run( ()=>Allocate2() ); not raises error. This lambda expression ()=>Allocate2() not returns Task. Why no error?
How to create task without lambda expression with function Allocate?
static async void Example() { int t = await Task.Run(Allocate); int t2 = await Task.Run( ()=>Allocate2() ); Console.WriteLine("Compute: " + t); } static Task<int> Allocate() { return 1; } static int Allocate2() { return 1; }
Task.RunreturnTask. What this task is doing inside is another story (see overloads).Cannot implicitly convert type 'int' to 'System.Threading.Tasks.Task<int>'because your return type isnt matched. but what is it that you are trying to acheive.Allocateasync and callvar t = await Allocate();