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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:39:53+00:00 2026-06-13T18:39:53+00:00

Ok, here’s the situation: My main/UI thread (call it Thread1) is used for acquiring

  • 0

Ok, here’s the situation: My main/UI thread (call it Thread1) is used for acquiring a batch of images from a phsycial document scanner. When a batch has been acquired, a separate “background” thread (call it Thread2) starts up to process and save the images from that batch.

Thread2 (the “background” thread) is using a Parallel.For loop which reduces the image processing/saving time by 70% over a normal For loop. However, it also appears to be maxing out all of my processors so that Thread1 can not start acquiring any more images until the Parallel.For loop completes.

Is there a way to “limit” a Parallel.For loop so that it does not max out my processors? Or to set the processing priority? I tried setting Thread2.Priority = ThreadPriority.Lowest, but this does not appear to affect the loop. Or am I misunderstanding how a Parallel.For loop works? Is it blocking Thread1 somehow?

Here is how I call the Thread2 from a method in Thread1.

public void SaveWithSettings(bool save) // method in Thread1
{
    ....
    Thread thr = new Thread(ThreadWork); // creating new thread (Thread 2)
    thr.Priority = ThreadPriority.Lowest; // does nothing?
    thr.Start(new SaveContainer(sc)); // pass a copy as paramater

    // misc stuff to make scanning possible again
    numBgw++;
    twain.RemoveAllImages(); // clear images
    imagelist.Clear(); // clear imagelist images
    .... // etc. this all appears to process fine while Thread2 is processing
}

Here is my ThreadWork method:

private void ThreadWork(object data) // executing in Thread2
{
    SaveContainer sc = data as SaveContainer; // holds images

    bool[] blankIndex = new bool[sc.imagelist.Count]; // to use in Parallel.For loop
    for (int i = 0; i < sc.imagelist.Count; i++)
        blankIndex[i] = false; // set default value to false (not blank)

    Parallel.For(0, sc.imagelist.Count, i => // loop to mark blank images
    {
        bool x = false; // local vars make loop more efficient
        x = sc.IsBlankImage((short)i); // check if image at index i is blank
        blankIndex[i] = x; // set if image is blank
    }
    .... // other image processing steps
}
  • 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-06-13T18:39:54+00:00Added an answer on June 13, 2026 at 6:39 pm

    OK, I figured it out! I’m only posting this in case someone ever inadvertantly has this happen to them…

    It turns out that the Parallel.For thread was NOT blocking Thread1 (yes, you were all right). HOWEVER, an object in Thread1 was trying to grab a new Thread from the ThreadPool while the loop was crunching away, and thus the “delay” occured. I’m using a 3rd party SDK that allows me to interact with the TWAIN interface and there was an option ScanInNewThread = true that was attempting to grab a new thread each time the user started a new scan (which was occuring while the loop was crunching away). I was able to change this so that a single (but still separate) thread is used throughout an application session instead of grabbing a new thread for each scan batch, and BANG, no more noticeable delay.

    SO – the moral of the story:

    Existing threads should still function “normally” (with the exception of the thread calling the Parallel.For loop) as long as they are not trying to grab more threads from the ThreadPool while the loop is going.

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

Sidebar

Related Questions

Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here's a piece of code I copied from http://www.schillmania.com/content/projects/javascript-animation-1/demo/ Very simple JS animation: function
Here's a dump of the stats provided my mod_pagespeed from one of my sites.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here is the code from my project where I am using a datepicker. The
Here I am trying to retrieve the response from the server and display it,
Here is my situation: I will have one frontend server running Nginx, and multiple
Here's the SQL query Select sum(f.Acres*m.credit1), sum(f.Acres*m.credit2), sum(f.Acres*m.credit3) from first f join model m
Here is my ajax call: var totalCost = 0; function GetTotalCost(start, end, rID) {

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.