In general we can await an async method invocation in any one of the Branch of execution. And other branches we can simply return. This will not give any warning.
But when we do the same in Parallel.ForEachAsync, We get the warning CS4014 "Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call."
await method1(null);
IEnumerable<string> collection = new List<string>();
Parallel.ForEachAsync(collection , async (obj, cancelationToken) => { //this statement gives warning
if (obj == null)
return;
else
await method2(obj);
});
async ValueTask method1(Object? obj) //But here there is no warning
{
if (obj == null)
return;
else
await method2(obj);
}
async Task method2(Object obj)
{
await Task.Delay(0);
}
What is the significance of warning here? Can we ignore this warning ? If not how to handle this ?