HOW to use Parallel For, ForEach in .NET

If you are running .NET-based development and multiprocessor, you can improve performance by parallel processing. For For, ForEach, which is often used for iterative data processing, you can experience up to 50% improvement in performance. Here, let’s compare it through ForEach. A typical ForEach statement is shown below.


Add using System.Threading.Tasks to the top for parallelism. Then change the ForEach statement as shown below.


One characteristic of parallel processing is that loop code must be grouped together.

Please note, however, that you can not use it in applications where sequential processing is required.

Facebook Comments

Leave A Reply

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다

This site uses Akismet to reduce spam. Learn how your comment data is processed.