I have a questions where If I run the Main method, with (GetRankedEditorsPickList) call inside it, it runs asynchronously but with (GetRankedEditorsPickList1) it runs sequentially. You can see the managed threadId and results.
Can someone give me an idea why?. This is linqpad code.
async Task Main()
{
List<string> y = new List<string>() { "a","b","c" };
var rankedFeedBatchTasks = y.Select(async (batch, index) =>
{
return new
{
Index = index,
RankedList = await GetRankedEditorsPickList1(batch).ConfigureAwait(false)
};
}).ToList();
var rankedFeedBatches = await Task.WhenAll(rankedFeedBatchTasks);
"Completed".Dump();
}
async Task<string> GetRankedEditorsPickList(string batch)
{
$"Started + {Environment.CurrentManagedThreadId}".Dump();
await Task.Delay(TimeSpan.FromSeconds(5));
batch = batch + "1";
$"Ended + {Environment.CurrentManagedThreadId}".Dump();
return batch;
}
// Define other methods and classes here
Task<string> GetRankedEditorsPickList1(string batch)
{
$"Started + {Environment.CurrentManagedThreadId}".Dump();
Thread.Sleep(TimeSpan.FromSeconds(5));
batch = batch + "1";
$"Ended + {Environment.CurrentManagedThreadId}".Dump();
return Task.FromResult(batch);
}
First method calls Results ::
Started + 11
Started + 11
Started + 11
Ended + 10
Ended + 13
Ended + 14
Completed
Second Method calls Results ::
Started + 11
Ended + 11
Started + 11
Ended + 11
Started + 11
Ended + 11
Completed