✅ Foreach vs Parallel.ForEach with Async mehtods

I recently changed my code who had foreach to Parallel.Foreach. This foreach has multiples asynchronous methods and when i run with simple foreach ,the methods are called normally but, when i changed foreach to Parallel.Foreach looks like the code not work well , he literally goes crazy, one time runs ok and other time throws exception , why this occurs ? Am i done something wrong ? My project are in .NET CORE 3.1. Follow my code with foreach and Parallel.Foreach.
3 Replies
mtreit
mtreit2y ago
Not addressing your question, but you realize .NET Core 3.1 is out of support... Also, what exception? You might have thread safety issues. Also, your serialized await calls feel like they could be run in parallel...
スカー藩主 NTSC #JusticeForJoost
I think you shouldn't execute async functions in a separate thread Because your global work is already parallelized
Omnissiah
Omnissiah2y ago
also are all the awaits in the else necessarily sequential? is Task.WhenAll an option?
Want results from more Discord servers?
Add your server