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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:58:32+00:00 2026-05-22T15:58:32+00:00

I have the following PLINQ statement in a C# program: foreach (ArrestRecord arrest in

  • 0

I have the following PLINQ statement in a C# program:

 foreach (ArrestRecord arrest in
            from row in arrestQueue.AsParallel()
            select row)
        {
            Geocoder geocodeThis = new Geocoder(arrest);
            writeQueue.Enqueue(geocodeThis.Geocode());
            Console.Out.WriteLine("Enqueued " + ++k);
        }

Both arrestQueue and writeQueue are ConcurrentQueues.

Nothing is running in parallel:

  • While running, total CPU usage is about 30%, and this is with everything else running, too. I have 8 cores (Hyper-Threading on a Core i7 720QM with 4 physical cores), and 4 of the 8 cores have virtually no utilization at all. The rest run roughly 40%-50%.
  • Disk usage is usually 0%, and there’s no network usage except for queries to a Postgres DB on localhost (see below).
  • If I add a breakpoint somewhere inside geocodeThis.Geocode(), Visual Studio’s Thread dropdown just says [pid] Main Thread. It never goes to any other thread.
  • I am using Npgsql to connect to Postgres, and each thread runs a few SELECT queries against a table. I am running pgAdmin III’s Server Status app, which shows pg_stat_activity. Through monitoring this, and strategic breakpoint placement (see above), I can see that the app never has more than 1 database connection open for all supposedly concurrent threads running geocodeThis.Geocode(). Even if I add Pooling=false to the DB connection string, to force connections not to be pooled, I never see more than 1 connection used in geocodeThis.Geocode().
  • The Postgres table is indexed on every column in the WHERE clause. Even if it was poorly indexed, I’d expect lots of disk usage. If Postgres was holding things up in any other way, seems like it would soak a core.

This seems like a simple PLINQ case study, and I am scratching my head as to why nothing’s running in parallel.

  • 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-22T15:58:32+00:00Added an answer on May 22, 2026 at 3:58 pm

    You are parallelizing just the enumeration of the assertQueue itself and then “unparallelizing” it back into an ordinary IEnumerable. This all happens before the foreach loop even starts. Then you use the ordinary IEnumerable with the foreach which runs the body of the loop serially.

    There are many ways to run the body of the loop in parallel but the first one that comes to mind is using Parallel.ForEach:

    Parallel.ForEach(arrestQueue, arrest =>
        {
            Geocoder geocodeThis = new Geocoder(arrest);
            writeQueue.Enqueue(geocodeThis.Geocode());
            Console.Out.WriteLine("Enqueued " + ++k);
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have following String built SQL query: StringBuilder querySelect = new StringBuilder(select * from messages
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have the following LINQ query var meshesList= ( from element in elementCoord.Elements let
I have following setup. from django.db import models from django.contrib.auth.models import User class Event(models.Model):
I have following batch file code: @echo off SET INSTALL_PATH=c:\program files\ :ask_again if exist
I have following Structure in my Program. #define WIFI_DEVICE_NAME 100 #define WIFI_SERIAL_NO 13 #define
I have following problem: My program should decide at runtime to load an function
Have following validation for year value from text input: if (!year.match(new RegExp('\\d{4}'))){ ... }
I have following code import sys from ctypes import * from ctypes.util import find_library
I have following LINQ statement: string[] str = { a, ab, abcd }; var

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.