This question already has an answer here:
- Cannot convert lambda expression to type “…” because it is not a delegate type 2 answers
I need to create a function which will return a task that will be executed at another time.
I would like for that task to return a value (preferably through await
ing it).
I would also like to be able to await
methods/functions within that task.
When I try to create a simple conceptual function which should do what I want, I get a red-line error message :
private static Task<object> FooGet( ) {
return new Task<object>( async ( ) => {
await asyncBar( );
return new object( );
} );
}
The error reads : Cannot convert lambda expression to type 'object' because it is not a delegate type
As soon as I remove the async
keyword from the lambda, everything's hunky dory.
How can I fix this? Can I even fix this?