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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:57:22+00:00 2026-06-04T14:57:22+00:00

I have a function like this: private void GetRSS(int start, int end) { for

  • 0

I have a function like this:

private void GetRSS(int start, int end)
{
    for (int i = start; i < end; i++)
    {
        string content = string.Empty;
        using (WebClient client = new WebClient())
        {
            //some code here get html content
        }
        // some code here parse content
    }
}

In order to minimize the amount of time running to get all the needed data, I would like to run the function 4 times with different ranges at the same time and then merge the results or use a thread safe list or dictionary.

My question is, how could I run this function in 4 separated threads and still be able to control if one of the threads still working or not to know when it ends ?

My first idea was to declare each thread:

private Thread _controler;
private Thread _worker1;
private Thread _worker2;
private Thread _worker3;
private Thread _worker4;
private bool _isRunning = false;

Then I would start the controler and from inside the controler I would call each thread to execute the function above and keep track of each thread from the controler, something like:

private void _ControlerStart()
{
    _worker1 = new Thread(GetRSS);
    try
    {
        _worker1.Start(1, 7711);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
    // repeat the above to all the 4 threads
    _isRunning = true;
    while (_isRunning)
    {
        if (_worker1.ThreadState != ThreadState.Running && _worker2.ThreadState != ThreadState.Running && _worker3.ThreadState != ThreadState.Running && _worker4.ThreadState != ThreadState.Running)
            _isRunning = false;
    }
    MessageBox.Show("Done");
}

While thinking on all this mess above I realize d that this is not the best way to do what I wanted and here I am ;).

How can I manage more than 1 thread to run the same function and yet be able to know when each thread has ended working to close or save or merge the data or do whatever else I have left to do from a main thread?

  • 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-04T14:57:23+00:00Added an answer on June 4, 2026 at 2:57 pm
    private static void GetRSS(int start, int end)
    {
        var bunchSize = (end - start) / 4 + 1;
    
        var threads = new List<Thread>();
    
        for (int i = 0; i < 4; i++)
        {
            var currStart = start + i * bunchSize;
            var currEnd = currStart + bunchSize;
    
            if (currEnd > end)
            {
                currEnd = end;
            }
    
            var thread = new Thread(() =>
                                        {
                                            // thread logic using currStart and currEnd
    
                                            string content = string.Empty;
                                            using (WebClient client = new WebClient())
                                            {
                                                //some code here get html content
                                            }
                                            // some code here parse content
                                        });
    
            threads.Add(thread);
            thread.Start();
        }
    
        foreach (var thread in threads)
        {
            thread.Join();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function like this in actionscript3 private function uploadFile(event:MouseEvent):void { var uploader:URLRequest
I have a ComboBox with a label function like this one: private function fieldLabelFunction(item:Object):String
I have code like this: private var video:Video; ... private function init():void { ...
I have 2 overloaded C# functions like this: private void _Insert(Hashtable hash, string tablename,
So if I have a function like this in c# (#1) private void Test(){
I have a function, like this, private void Step() { foreach (A a in
I have an array of function callbacks, like this: class Blah { private var
I have a function defined like this: public static void ShowAbout(Point location, bool stripSystemAssemblies
Since the advent of AS3 I have been working like this: private var loggy:String;
If I have a method declared like this: private void someFunction(object[] param1) When I

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.