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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:54:30+00:00 2026-06-11T00:54:30+00:00

I have a thread, call it the Parsing thread. Thread parsingThread = new Thread(myMethod);

  • 0

I have a thread, call it the “Parsing thread”.

Thread parsingThread = new Thread(myMethod);

I perform some computations on this thread, of which the last involves more parallel computations.

    public void ReadCityFiles(BlockingCollection<GeonamesFileInfo> files)
    {
        Parallel.ForEach<GeonamesFileInfo>(
            files.GetConsumingPartitioner<GeonamesFileInfo>(),
            new ParallelOptions { MaxDegreeOfParallelism = _maxParallelism },
            (inputFile, args) =>
            {
                RaiseFileParsing(inputFile);
                using (var input = new System.IO.StreamReader(inputFile.FullName))
                {
                    while (!input.EndOfStream)
                    {
                        RaiseEntryParsed(ParseCity(input.ReadLine()));
                        Interlocked.Increment(ref _parsedEntries);
                    }
                }
                RaiseFileParsed(inputFile);
            });
        RaiseDirectoryParsed(Directory);
    }

The problem is that when these very long and computationally expensive async foreach operations finish (~30 mins), the “Parsing Thread” doesn’t resume. My GUI is still responsive, but the RaiseDirectoryParsed function that is supposed to continue to run on the “Parsing Thread” is never called. I debugged the program up to this point, and am pretty baffled as to what to do in this situation.

  • 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-11T00:54:32+00:00Added an answer on June 11, 2026 at 12:54 am

    The point of BlockingCollection is that when an operation cannot be performed now, but might be in the future (e.g. Take() or Add() on a collection with bounded capacity), it will block. The same applies to GetConsumingEnumerable() and thus also to GetConsumingPartitioner(): if the collection is currently empty, the enumerable will block until you add more items to the collection.

    But there is also a way to tell the collection that you’re not going to add new items anymore and that it shouldn’t block when empty from now on: the CompleteAdding() method. If you call this when you know you won’t be adding any more new items to the collection, your Parallel.ForEach() won’t block anymore and your thread will continue executing.

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

Sidebar

Related Questions

I have the following function call from a thread: Thread Move = new Thread(){
I have this code inside thread and when I call terminate it terminates fast
I'm developing an application on the Android system which involves parsing some xml stuff.
I have a Cocoa app which launches a new NSThread (Thread A) from within
I have a simple exercise where I call a Thread and subsequently the run()
I'd like to have two Threads. Let's call them : Thread A Thread B
I have a program with three threads. I call them like this: if __name__
I have thread where downloading xml file a this xml file i want to
I have a multi-threaded application which parses some text and it needs to use
I have many threads using the below interface ServerMessage If many threads call the

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.