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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:00:38+00:00 2026-05-26T05:00:38+00:00

I am trying to parallelize a query with a groupby statement in it. The

  • 0

I am trying to parallelize a query with a groupby statement in it. The query is similar to

    var colletionByWeek = (
                             from item in objectCollection
                             group item by item.WeekStartDate into weekGroups
                             select weekGroups
                          ).ToList();

If I use Parallel.ForEach with shared variable like below, it works fine. But I don’t want to use shared variables in parallel query.

var pSummary=new List<object>();
Parallel.ForEach(colletionByWeek, week =>
                                {
                                    pSummary.Add(new object()
                                    {
                                        p1 = week.First().someprop,
                                        p2= week.key,
                                        .....
                                    });
                                }
                 );  

So, I have changed the above parallel statement to use local variables. But the compiler complains about the source type <IEnumerable<IGrouping<DateTime, object>> can not be converted into System.Collections.Concurrent.OrderablePartitioner<IEnumerable<IGrouping<DateTime, object>>.

Am I giving a wrong source type? or is this type IGouping type handled differently? Any help would be appreciated. Thanks!

 Parallel.ForEach<IEnumerable<IGrouping<DateTime, object>>, IEnumerable<object>>
                        (spotColletionByWeek,
                         () => new List<object>(),
                         (week, loop, summary) =>
                         {
                             summary.Add(new object()
                             {
                                            p1 = week.First().someprop,
                                            p2= week.key,
                                            .....
                           });
                             return new List<object>();
                         },
                         (finalResult) => pSummary.AddRange(finalResult)
                        );
  • 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-26T05:00:39+00:00Added an answer on May 26, 2026 at 5:00 am

    The type parameter TSource is the element type, not the collection type. And the second type parameter represents the local storage type, so it should be List<T>, if you want to Add() to it. This should work:

    Parallel.ForEach<IGrouping<DateTime, object>, List<object>>
    

    That’s assuming you don’t actually have objects there, but some specific type.

    Although explicit type parameters are not even necessary here. The compiler should be able to infer them.

    But there are other problems in the code:

    • you shouldn’t return new List from the main delegate, but summary

    • the delegate that processes finalResult might be executed concurrently on multiple threads, so you should use locks or a concurrent collection there.

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

Sidebar

Related Questions

I am trying to work out how to parallelize some code from data mining
I'm trying to parallelize a convolution function in C. Here's the original function which
Trying to make a MySQL-based application support MS SQL, I ran into the following
I'm trying to parallelize the element by element multiplication of two matrices in F#.
I'm trying to a parallelize an application using multiprocessing which takes in a very
I was considering trying PLINQ to parallelize some numerical methods which need to be
I am trying to parallelize an old Makefile. In fact I need to make
I'm trying to use the Task-Parallel-Library to offload expensive ADO.NET database access from the
Trying to launch and pass tel. no. to skype by this code from my
I'm trying to parallelize a ray tracer in C, but the execution time is

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.