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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:29:45+00:00 2026-06-08T10:29:45+00:00

So, I’ll make an application for checking links if they’re accessible(live). My question is

  • 0

So, I’ll make an application for checking links if they’re accessible(live).
My question is how to make the threads “always busy”. What I mean:
The app run 100 threads(created with FOR loop for example) with 100 different URLs. So when 1 of the threads finish it’s job(check if URL is available) to get new URL and start again immediately. So the 100 threads will work non-stop till all URLs are checked.

How can I accomplish that?

  • 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-08T10:29:47+00:00Added an answer on June 8, 2026 at 10:29 am

    What you are looking for is called the Producer-Consumer Model. You have a pool of resources, that contains the list of urls to check, one thread can fill that pool, and your conumer threads can pull from that pool, if you have .NET 4 Parallel.ForEach does most of the work for you.

    Using 100 threads also is very likely not going to be the optimum number of threads, just let the Task Parallel Library manage the thread count for you.

    Here is a example if the list will be pre-populated and not have more items added as the thread is running.

    //Parallel.Foreach will block until it is done so you may want to run this function on a background worker.
    public void StartThreads()
    {
        List<string> myListOfUrls = GetUrls();
    
        Parallel.Foreach(myListOfUrls, ProcessUrl);
    }
    
    
    private void ProcessUrl(string url)
    {
        //Do your work here, this code will be run from multiple threads.
    }
    

    If you need to populate the collection as it runs, replace List<string> with a concurrent collection like BlockingCollection

    BlockingCollection<string> myListOfUrls = new BlockingCollection();
    
    //Parallel.Foreach will block until it is done so you may want to run this function on a background worker.
    public void StartThreads()
    {
        if(myListOfUrls.IsComplete == true)
        {
            //The collection has emptied itself and you told it you where done using it, you will either need to throw a exception or make a new collection.
            //use IsCompleatedAdding to check to see if you told it that you are done with it, but there still may be members left to process.
            throw new InvalidOperationException();
        }
    
        //We create a Partitioner to remove the buffering behavior of Parallel.ForEach, this gives better performance with a BlockingCollection.
        var partitioner = Partitioner.Create(myListOfUrls.GetConsumingEnumerable(), EnumerablePartitionerOptions.NoBuffering);
        Parallel.ForEach(partitioner, ProcessUrl);
    }
    
    public void StopThreads()
    {
        myListOfUrls.CompletedAdding()
    }
    
    public void AddUrl(string url)
    {
        myListOfUrls.Add(url);
    }
    
    private void ProcessUrl(string url)
    {
        //Do your work here, this code will be run from multiple threads.
    }
    

    I also wanted to add that the automated thread scheduling may not be the best also, it may put some limits that could be expanded on, see this comment from the original question

    For those, who said/upvoted 100 thread is a terrible idea: On my dual
    core 2GB RAM XP machine Parallel.Foreach never created more than 5
    threads(unless I set ThreadPool.SetMinThreads) and creating 100
    threads resulted always ~30-40% faster operation. So don’t leave
    everything to Parallel.Foreach . PS: My test code WebClient wc = new
    WebClient();var s = wc.DownloadString(url); (google’s home page) – L.B

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

Sidebar

Related Questions

I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I want to count how many characters a certain string has in PHP, but

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.