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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:06:50+00:00 2026-05-23T01:06:50+00:00

I have a C# console app where I have a threadpool. In the threadpool

  • 0

I have a C# console app where I have a threadpool. In the threadpool there will be a class thats executes a continuous method (till it has ran for a certain period of time or when it knows when to stop). The method connects to an HttpWebResponse stream and keep reeding it.

The problem is that for a short time all threads just do their things but then only one threads keep showing it’s output and the rest is waiting for that thread.

This is the method that is executed for each thread.

function void ReadStream()
        byte[] buf = new byte[8192];

        String domain = streamingUrl

        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(domain);
        HttpWebResponse response = (HttpWebResponse)
        request.GetResponse();

        Stream resStream = response.GetResponseStream();

        string tempString = null;
        int count;
        do
        {
            // fill the buffer with data
            count = resStream.Read(buf, 0, buf.Length);

            if (count != 0)
            {
                tempString = Encoding.ASCII.GetString(buf, 0, count);

                try
                {
                    mySqlManager.SaveResult(tempString);

                    Console.WriteLine("Been here");
                    Thread.Sleep(1000);
                }
                catch (Exception e)
                {
                }
            }
        }
        while (count > 0);
    }
  • 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-23T01:06:51+00:00Added an answer on May 23, 2026 at 1:06 am

    Firstly, you should wrap both response and resStream in using blocks to ensure they are disposed of properly.

    Second, putting long-running threads in the ThreadPool is not really the best idea, in my opinion. The idea of the ThreadPool class is that it allows you to queue up relatively small actions where spawning a new thread for each one would be wasteful. If you have operations that will take a significant amount of time to run, I would advise actually creating dedicated Thread objects for each.

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

Sidebar

Related Questions

I have console app A that references another console app B. B app has
I have a console app that's geared to be automatically ran as a Scheduled
I have a .Net console App which using a scheduled event will start, call
I have a console app that I'm porting to WPF. The application has 3
I have a console app that will choose records based on if the user
I have a console app, and a class library. I'm making changes to the
We have a .NET console app that has many foreground threads. If we kill
I have a console app that will be running through a scheduled task and
I have a console app in c# thats starts on schuled times by the
I have a Console App and in the main method, I have code like

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.