I have the following method that returns before it completes (method cut down for brevity):
private void ProcessAllItems(List<Item> items)
{
items.ForEach(async item =>
{
var response = await Processor.IOBoundTaskAsync(item);
// Some further processing on the response object.
});
}
The Processor.IOBoundTaskAsync method returns a Task<SomeResponseObject>, so not a void.
So, what is happening?
I want the lambda foreach to process each item one at a time, so not in parallel. For the first iteration, the code goes into the IOBoundTaskAsync and gets as far as the first "await" (where it calls the first of 4 awaited web service methods) and then the calling method "ProcessAllItems" exits.
I'm only using test data, so my list only has 1 item in it.
What am I missing?