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 616257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:18:27+00:00 2026-05-13T18:18:27+00:00

i have an extension method for IEnumerable which then iterates through the collection, doing

  • 0

i have an extension method for IEnumerable which then iterates through the collection, doing its business, and then returns an new IEnumerable.

I have tried to use PLINQ using .AsParallel().ForAll() which speeds up the iterations significantly (which of course it should do) however when the collection is returned, there are often a few objects in that collection that are null.

I’m assuming this may be because it is returning the collection before all the ‘business’ has a chance to complete? if i debug and put in a breakpoint, there are no nulls.

is there some sort of ‘wait for this operation to be completed’ method that i should be using?

EDIT: to be a bit clearer, there is business logic in the forall, modifying properties etc. it’s necessary to have an action looped, rather than simply selecting something.

  • 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-13T18:18:28+00:00Added an answer on May 13, 2026 at 6:18 pm

    The answer depends on what you mean by returning, because the ForAll method doesn’t return anything. It invokes the delegate you specify in parallel for all elements of the collection. I would suppose that your code looks like this:

    data.AsParallel().ForAll(() => /* calculate and store result somewhere */);
    // more code
    

    The ForAll method doesn’t wait for all delegates to complete, so more code can execute before all the delegates complete (and you also need to be careful in the store result somewhere bit, because it may run concurrently for multiple delegates!)

    I think the code could be rewritten more elegantly using the Select method:

    var res = data.AsParallel().Select(() => /* calculate the result */);
    

    In this case, the delegate simply returns the result. The Where method collects all the results and when you iterate over the returned IEnumerable, it guarantees that all delegates finished calculating.

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

Sidebar

Ask A Question

Stats

  • Questions 326k
  • Answers 326k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you're talking about the MySQL binary log file (mysql-bin),… May 14, 2026 at 1:43 am
  • Editorial Team
    Editorial Team added an answer In order to do this you'll need to create a… May 14, 2026 at 1:43 am
  • Editorial Team
    Editorial Team added an answer $cartLimiter[$itemNo] = $cartQuantity; May 14, 2026 at 1:43 am

Related Questions

I have an extension method with the following signature (in BuildServerExtensions class):: public static
Can anyone help? I have a linq query which is embedded inside a extension
Lets say I have something called Stuff in my database, with a property called
I really hate sometimes how IDictionary<TKey, TValue> [key] will throw an exception if the
I currently have an extension Method which converts an IEnumerable of type Tab into

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.