Relative Content

Tag Archive for c#async-awaitparallel-processingtasktask-parallel-library

Parallelism with async method: Why do I need to do Task.Run() here and can I avoid it?

I am aiming to improve my understanding regarding Concurrency in C# and ran into a question with a small toy problem I have.
Let’s consider an async method async Task<int> CountAsync(int id) that counts something based on a given ID, but for doing so, it has to make a web request for example, thus being async.
Now I would like to parallelize counting multiple different IDs. I asumed that that not awaiting each CountAsync call in a loop should do the job.