Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7540911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:45:26+00:00 2026-05-30T07:45:26+00:00

When I use Parallel.ForEach or Parallel.For in the System.Threading.Tasks namespace, can I assume that

  • 0

When I use Parallel.ForEach or Parallel.For in the System.Threading.Tasks namespace, can I assume that all threads are synchronised before execution continues?

Is there something equivalent to

WaitHandle.WaitAll(...);

going on?

So If I call something like

Parallel.ForEach(collection, DoSomethingWithObject);

Can I be certain that each call to DoSomethingWithObject has completed before ForEach returns, or do I need to use WaitHandles myself?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:45:28+00:00Added an answer on May 30, 2026 at 7:45 am

    All the tasks will have completed by the time Parallel.ForEach() returns, unless a call to Stop() was specifically made to abort the parallel execution. In such cases, the .IsCompleted property of the ParallelLoopState object returned by Parallel.ForEach() will be false.

    You can read about it here:

    http://msdn.microsoft.com/en-us/library/dd992001.aspx

    http://msdn.microsoft.com/en-us/library/system.threading.tasks.parallelloopresult.aspx

    You can also write a small test application where DoSomethingWithObject() is a very long running operation, or a call to Thread.Sleep(), to verify this. Execution will block until all threads have finished sleeping.

    Sample:

    Parallel.ForEach(Enumerable.Range(1, 8),
        i =>
        {
            Thread.Sleep(5000);
            Console.WriteLine(i + " done!");
        });
    Console.WriteLine("All done!");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am planning to use Parallel.ForEach on a DataTable so that each record can
I am refactoring my program to use Parallel.ForEach. Before, when I was using a
I would like to use the new Parallel.ForEach function to loop through a datatable
My question centers on some Parallel.ForEach code that used to work without fail, and
I have an IronPython script that uses the TPL and Parallel.ForEach to process files
Say I have a situation where I really want to use Parallel.ForEach instead of
Does it make sense to you to use for every normal foreach a parallel.foreach
use LWP::Simple; use Parallel::ForkManager; @links=( [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3D-2.1-windows.exe,SweetHome3D-2.1-windows.exe], [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3D-2.1-macosx.dmg,SweetHome3D-2.1-macosx.dmg], [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3DViewer-2.1.zip,SweetHome3DViewer-2.1.zip], ); # Max 30 processes for
How does one use multiprocessing to tackle embarrassingly parallel problems ? Embarassingly parallel problems
This article here suggests to use -XX:+UseParNewGC To enable a parallel young generation GC

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.