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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:22:09+00:00 2026-06-08T22:22:09+00:00

I want my forms application to start multiple threads to download the source code

  • 0

I want my forms application to start multiple threads to download the source code from a site in parallel.

This is just a part of the main application.

Link to the picture: http://www.abload.de/img/pic9aym7.png
I’m not allowed to post images.

    private void buttonstart_Click(object sender, EventArgs e)
    {
         //check the list below
    }

    private void buttonabort_Click(object sender, EventArgs e)
    {
         //should always could abort the process/threads. (close all webcontrols ect)
    }
  1. It should start to read the numeric in the box.
  2. foreach number it should open a webbrowser or httpwebrequest to download some source code and count the runs (in this example 4 runs).
    so if the website is like “http://www.bla.com/”, it should add the run to the end of the variable (http://www.bla.com/1-4).
  3. Parse the source into different strings. (strWebsiteString1, strWebsiteString2, and so on. I’ll need them later)

  4. if that is done, it should read some tables(from the strings) and parse them in to arrays. (same here array1[3], array2[3], for future use)
    To get the tables I think I will use htmlagilitypack.
    I’ve already coded this htmlagilitything for console. I just need to rebuild it for my forms application, and change console writeline to put it in some arrays.

    But I’m open to other/better solution.

  5. All my data I’ve parsed into the arrays should now been shown in the datagridcolumns.
    Each run will get its own row.
    But when I try to add items into the comboboxcolumn, I get errors at each and every comboboxcolumn.
  6. To get them in the right order and to know which browser data it is from, column1 will get the number of runs.

I’ve already tried by myself.
I get stuck with the threads respectively crossthreading.
And the datagridview makes a lot trouble too.

Do me a favour and help me to solve this problem and show me maybe show a snippet/sample what could help me.

  • 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-08T22:22:10+00:00Added an answer on June 8, 2026 at 10:22 pm

    This is a clear example demonstrating what I’ve stated on my comment above. It uses lock instead of Mutex but you’ll get the point. It’s a simple code using multi-threaded Job producers all adding informations to the same (locked) resource and one consumer running once every second to interact with a form control -ListBox in this case- and clear the jobs cache.

    You’ll find further informations here http://www.albahari.com/threading/part2.aspx

    public partial class Form1 : Form
    {
        static readonly Queue<Job> queue = new Queue<Job>();
    
        public Form1()
        {
            InitializeComponent();
            //starts the timer to run the ProcessJobs() method every second
            System.Threading.Timer t = new System.Threading.Timer(obj => { ProcessJobs(); }, null, 5000, 1000);                
        }               
    
        /// <summary>
        /// Called by informations producers to add jobs to the common queue
        /// </summary>        
        private void AddJob(Job job)
        {
            lock (queue)
            {
                queue.Enqueue(job);
            }
        }
    
        /// <summary>
        /// Common queue processing by the consumer
        /// </summary>
        private void ProcessJobs() {            
            Job[] jobs;
            lock (queue)
            {
                jobs = queue.ToArray();
                queue.Clear();
            }
            foreach(Job job in jobs){       
                this.Invoke(new Action(delegate {
                    listBox1.Items.Add(job.Name);
                }));
            }
        }
    
        /// <summary>
        /// Producer
        /// </summary>        
        private void JobsProducer(string name) {
            for (int i = 0; i < 10; i++)
            {
                Random r = new Random();
                System.Threading.Thread.Sleep(r.Next(1,10)*50);
                this.AddJob(new Job(string.Format("Job({0}) n.{1}", name, i)));
            }
        }
    
        /// <summary>
        /// Starts the jobs producers
        /// </summary>        
        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                string producerName = string.Format("Producer{0}", i);
                new System.Threading.Timer(obj => { JobsProducer(producerName); }, null, 0, System.Threading.Timeout.Infinite);
            }
        }       
    }
    
    public class Job
    {
        //whatever -informations you need to exchange between producer and consumer
        private string name;
        public string Name { get { return name; } }
        public Job(string name) {
            this.name = name;
        }
    }  
    

    And here you can find an example using the Dictionary to hold several jobs results:

    Dictionary<string, string[]> jobs = new Dictionary<string, string[]>();
    //adds an array to the dictionary
    //NB: (array it's not well suited if you don't know the values or the size in advance...you should use a List<string>)
    jobs.Add("jobNumber1", new string[]{"a","b"});
    //gets an array from the dictionary
    string[] jobNumber1;
    if (!jobs.TryGetValue("jobNumber1", out jobNumber1))
         throw new ApplicationException("Couldn't find the specified job in the dictionary"); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a windows forms c# application, i just want update items in
This is a Visual Studio Express C++ Windows Forms application. I want to play
Scenario I have a windows forms application. I want to use two different WCF
I am building a Windows forms application using VS2010. I want to read the
I am working on a Windows Forms application in C#/.Net. I want to use
I'm using OpenGL in C++ Visual Studio 2008 Forms application and I want a
I want to get Default Windows Forms Unhandled-Exception Dialog whenever my C# application encounters
I've developed a windows form application. However,I want to upload data from that application
I'm making a windows forms application in c# that will start in windows start
We have a large legacy application where we want to start using MVC for

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.