I wrote the code below,
Task.Factory.StartNew<int>(async () =>
{
await Task.Delay(1000);
return 42;
});
but the read line appeared under the "async" keyword, and the code cannot compiled due to some syntax error, can anybody advise me what to do?
Thx a lot!
You probably want to use Task.Run, which has more natural syntax for async lambdas:
var task = Task.Run(async () =>
{
await Task.Delay(1000);
return 42;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With