Click here to Skip to main content
15,889,403 members
Articles / Programming Languages / C#

Using Asynchrony Methods in Foreach Sentences

Rate me:
Please Sign up or sign in to vote.
4.25/5 (9 votes)
1 Nov 2021CPOL5 min read 37.1K   200   13  
The foreach loop and in any case, the for loop in C# can get a great benefit in performance by using await and Task instruction. But this is not always possible.
In this article, we analyze the use of await and Task.WhenAll in for-each loop in C#, when is possible or better use it, and how to avoid in some cases, the problem of concurrence and dependencies in the parallels execution of task inside the for-each.

Views

Daily Counts

Downloads

Weekly Counts

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Avalon Development
United States United States
Jose A. Garcia Guirado, Electronic Engineer, graduated in Havana/Cuba 1982, MCTS, MCSD.NET, MCAD.NET, MCSE. Worked in the Institute for Cybernetics and Mathematics of Academy of Science of Cuba for 8 years; since 1995 working as free software architect, developer and adviser, first in Argentina and from 2003 to 2010, in Germany as External consultant in DWS Luxembourg, AIXTRON AG and Shell Deutschland GmbH and from 2010 to 2012 in Mexico working for Twenty Century Fox, and Mexico Stock Exchange (BMV). From 2013 to now in USA, Florida, First in FAME Inc. and now as Senior Software Engineer in Spirit Airlines.

Comments and Discussions