{"id":55916,"date":"2010-04-21T09:00:00","date_gmt":"2010-04-21T09:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/pfxteam\/2010\/04\/21\/when-to-use-parallel-foreach-and-when-to-use-plinq\/"},"modified":"2010-04-21T09:00:00","modified_gmt":"2010-04-21T09:00:00","slug":"when-to-use-parallel-foreach-and-when-to-use-plinq","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/when-to-use-parallel-foreach-and-when-to-use-plinq\/","title":{"rendered":"When To Use Parallel.ForEach and When to Use PLINQ"},"content":{"rendered":"<p>If you&#8217;ve played around with PLINQ and&nbsp;Parallel.ForEach loops&nbsp;in .NET 4, you may have noticed that many PLINQ queries can be rewritten as&nbsp;parallel loops, and also many&nbsp;parallel loops can be rewritten as PLINQ queries. However, both parallel loops and PLINQ&nbsp;have distinct&nbsp;advantages in different situations. When writing parallel code, it helps to understand these differences to appropriately decide between the two models.<\/p>\n<p>Pamela Vagata wrote an interesting comparison of parallel loops and PLINQ: <a title=\"When Should I Use Parallel.ForEach? When Should I Use PLINQ?\" href=\"http:\/\/download.microsoft.com\/download\/B\/C\/F\/BCFD4868-1354-45E3-B71B-B851CD78733D\/WhenToUseParallelForEachOrPLINQ.pdf\"><span style=\"color: #0066dd\">When Should I Use Parallel.ForEach? When Should I Use PLINQ?<\/span><\/a><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve played around with PLINQ and&nbsp;Parallel.ForEach loops&nbsp;in .NET 4, you may have noticed that many PLINQ queries can be rewritten as&nbsp;parallel loops, and also many&nbsp;parallel loops can be rewritten as PLINQ queries. However, both parallel loops and PLINQ&nbsp;have distinct&nbsp;advantages in different situations. When writing parallel code, it helps to understand these differences to appropriately [&hellip;]<\/p>\n","protected":false},"author":481,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[7908],"tags":[7907,7922,7909,7910,7912],"class_list":["post-55916","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pfxteam","tag-net-4","tag-article-summary","tag-parallel-extensions","tag-plinq","tag-task-parallel-library"],"acf":[],"blog_post_summary":"<p>If you&#8217;ve played around with PLINQ and&nbsp;Parallel.ForEach loops&nbsp;in .NET 4, you may have noticed that many PLINQ queries can be rewritten as&nbsp;parallel loops, and also many&nbsp;parallel loops can be rewritten as PLINQ queries. However, both parallel loops and PLINQ&nbsp;have distinct&nbsp;advantages in different situations. When writing parallel code, it helps to understand these differences to appropriately [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/55916","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/481"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=55916"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/55916\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=55916"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=55916"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=55916"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}