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

  • SEARCH
  • Home
  • 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 6130391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:51:11+00:00 2026-05-23T16:51:11+00:00

I have question. Are there any benefits of using Parallel.Invoke inside of another Parallel.ForEach?

  • 0

I have question.

Are there any benefits of using Parallel.Invoke inside of another Parallel.ForEach?

Here is my code:

    Parallel.ForEach(yearMonths,
                     () => new List<DJVSStatsCo>(),
                     (yearMonth, loopState, localDjvsStatsCo) =>
                         {
                             var coVintageCounter = 0;
                             var coExitsCounter = 0;
                             var coExtant = 0;

                             Parallel.Invoke(() =>
                                             coVintageCounter = globalData.ValuationEventsPit.
                                                                    Where(x => x.FirstRoundYearMonth <= yearMonth).
                                                                    Select(x => x.CompanyId).Distinct().Count(),
                                             () =>
                                             coExitsCounter = globalData.ValuationEventsPit.
                                                                  Where(x => x.ExitDate != null && x.ExitDateYearMonth == yearMonth).
                                                                  Select(x => x.CompanyId).Distinct().Count(),
                                             () =>
                                             coExtant = globalData.ValuationEventsPit.
                                                            Where(x => x.FirstRoundYearMonth <= yearMonth && (x.ExitDate == null || x.ExitDateYearMonth > yearMonth)).
                                                            Select(x => x.CompanyId).Distinct().Count()
                                 );

                             localDjvsStatsCo.Add(new DJVSStatsCo(yearMonth, coVintageCounter, coExtant, coExitsCounter));

                             return localDjvsStatsCo;
                         },
                     x =>
                         {
                             lock (locker)
                             {
                                 djvsStatsCos.AddRange(x);
                             }
                         });

I have about 50K records and my machine has 2 core processors and calculating calc time I am getting almost the same result. So my question is are there any benefits of using Parallel inside of Parallel? What is the best practice for this?

Thanks a lot.

Sincerely,
Vlad.

  • 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-23T16:51:11+00:00Added an answer on May 23, 2026 at 4:51 pm

    In this case, there’s probably no benefit. There could be a benefit in the case where you have relatively few “outer” jobs, but potentially many “inner” jobs.

    On the other hand, it also depends on what those three jobs are doing. If they’re essentially asynchronous tasks (e.g. on the database) which can be executed in parallel, then sure… but if they’re local CPU-intensive tasks, then you’re probably just going to give extra work to the scheduler for no real benefit.

    Given the look of your code, it strikes me that you could quite possibly benefit from performing a single query (or maybe three) and grouping by yearMonth though…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a general question about interpreters of functional languages: Are there actually any
Hey just a quick question for any experts out there. I have a site
Hey guys, one more quick question for any experts out there. I have a
Are there any benefits to using the 'window' prefix when calling javascript variables or
Actually I have two questions. (1) Is there any reduction in processing power or
I have Question and QuestionTypes. In Question table there is a foreign key that
I have a question about why there is such a difference in speed between
I have a job interview tomorrow and I'm trying to answer this question: There
I have a question about SqlDataReader: Is there some way to modificated the values
i have a question ( i am learning VB) is there is a way

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.