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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:16:24+00:00 2026-05-28T05:16:24+00:00

I have WPF app that processes a lot of urls (thousands), each it sends

  • 0

I have WPF app that processes a lot of urls (thousands), each it sends off to it’s own thread, does some processing and stores a result in the database.

The urls can be anything, but some seem to be massively big pages, this seems to shoot the memory usage up a lot and make performance really bad. I set a timeout on the web request, so if it took longer than say 20 seconds it doesn’t bother with that url, but it seems to not make much difference.

Here’s the code section:

               HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(urlAddress.Address);
                            req.Timeout = 20000;
                            req.ReadWriteTimeout = 20000;
                            req.Method = "GET";
                            req.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;

                            using (StreamReader reader = new StreamReader(req.GetResponse().GetResponseStream()))
                            {
                                pageSource = reader.ReadToEnd();
                                req = null;
                            }

It also seems to stall/ramp up memory on reader.ReadToEnd();

I would have thought having a cut off of 20 seconds would help, is there a better method? I assume there’s not much advantage to using asynch web method as each url download is on its own thread anyway..

Thanks

  • 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-28T05:16:24+00:00Added an answer on May 28, 2026 at 5:16 am

    In general, it’s recommended that you use asynchronous HttpWebRequests instead of creating your own threads. The article I’ve linked above also includes some benchmarking results.

    I don’t know what you’re doing with the page source after you read the stream to end, but using string can be an issue:

    System.String type is used in any .NET application. We have strings
    as: names, addresses, descriptions, error messages, warnings or even
    application settings. Each application has to create, compare or
    format string data. Considering the immutability and the fact that any
    object can be converted to a string, all the available memory can be
    swallowed by a huge amount of unwanted string duplicates or unclaimed
    string objects.

    Some other suggestions:

    • Do you have any firewall restrictions? I’ve seen a lot of issues at work where the firewall enables rate limiting and fetching pages grinds down to a halt (happens to me all the time)!
    • I presume that you’re going to use the string to parse HTML, so I would recommend that you initialize your parser with the Stream instead of passing in a string containing the page source (if that’s an option).
    • If you’re storing the page source in the database, then there isn’t much you can do.
    • Try to eliminate the reading of the page source as a potential contributor to the memory/performance problem by commenting it out.
    • Use a streaming HTML parser such as Majestic 12– avoids the need to load the entire page source into memory (again, if you need to parse)!
    • Limit the size of the pages you’re going to download, say, only download 150KB. The average page size is about 100KB-130KB

    Additionally, can you tell us what’s your initial rate of fetching pages and what does it go down to? Are you seeing any errors/exceptions from the web request as you’re fetching pages?

    Update

    In the comment section I noticed that you’re creating thousands of threads and I would say that you don’t need to do that. Start with a small number of threads and keep increasing them until you peek the performance on your system. Once you start adding threads and the performance looks like it’s tapered off, then sop adding threads. I can’t imagine that you will need more than 128 threads (even that seems high). Create a fixed number of threads, e.g. 64, let each thread take a URL from your queue, fetch the page, process it and then go back to getting pages from the queue again.

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

Sidebar

Related Questions

I have a WPF app that uses DataGrid to display some data. When I
I have some user admin functionality in a WPF app that I'm currently writing
I have a WPF App that implements a ListView. I would like to show
I have a WPF app that is using the MVVM pattern. Hooking up buttons
I have a wpf app that needs to communicate(exchange data) with a custom designed
We have a WPF app that allows our users to download encrypted content and
I have a WPF app, my purpose is that the app can be automatically
I have a folder in my WPF app Images that has several .png files
Ok, I have a ResourceDictionary definition that I used for a WPF app below:
I have a WPF application that is a fullscreen kiosk app. It's actually a

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.