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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:35:16+00:00 2026-06-11T06:35:16+00:00

In this case the progressBar is moving faster then the real Dowork progress then

  • 0

In this case the progressBar is moving faster then the real Dowork progress then throw exception in the progressChanged event that the progressBar value is over 100% then whats wrong here how do i calculate and report it the right way ?

private List<string> webCrawler(string url, int levels , DoWorkEventArgs eve)
        {
            bool already = false;
                HtmlAgilityPack.HtmlDocument doc;
                HtmlWeb hw = new HtmlWeb();
                List<string> webSites;// = new List<string>();
                List<string> csFiles = new List<string>();

                csFiles.Add("temp string to know that something is happening in level = " + levels.ToString());
                csFiles.Add("current site name in this level is : " + url);
                                try
                {
                    doc = hw.Load(url);
                    webSites = getLinks(doc);


                    if (levels == 0)
                    {
                        return csFiles;
                    }
                    else
                    {

                        int actual_sites = 0;
                        for (int i = 0; i < webSites.Count() && i < 20; i++)                         {
                            if ((worker.CancellationPending == true))
                            {
                                eve.Cancel = true;
                                break;
                            }
                            else
                            {

                                string t = webSites[i];
                                                                if ((t.StartsWith("http://") == true) || (t.StartsWith("https://") == true)) // replace this with future FilterJunkLinks function
                                {
                                    for (int e = 0; e < csFiles.Count; e++)
                                    {
                                        if (csFiles[e].Contains(t))
                                        {
                                            already = true;

                                        }
                                    }

                                    if (!already)
                                    {
                                        actual_sites++;
                                        csFiles.AddRange(webCrawler(t, levels - 1,eve));
                                        this.Invoke(new MethodInvoker(delegate { Texts(richTextBox1, "Level Number " + levels + " " + t + Environment.NewLine, Color.Red); }));
                                        worker.ReportProgress(i * 10);
                                                                            }

                                }
                            }
                        }

                        return csFiles;
                    }



                }
                catch
                {
                    return csFiles;
                }

        }




        public void Texts(RichTextBox box, string text, Color color)
        {
            box.SelectionStart = box.TextLength;
            box.SelectionLength = 0;

            box.SelectionColor = color;
            box.AppendText(text);
            box.SelectionColor = box.ForeColor;
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            worker = sender as BackgroundWorker;
            webCrawler(guys, 2,e);
        }

        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            this.progressBar1.Value = e.ProgressPercentage;

        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            backgroundWorker1.RunWorkerAsync();
        } 

I passed the variable e of the DoWorkEventsArgs in the DoWork event so i can use the worker variable in the webCrawler function if i need to cancel the operation. In the webCrawler im calling it DoWorkEventArgs eve.

The problem is that the report to the progressBar is not the right way.

Tried the reportprogress as:

for (int i = 0; i < webSites.Count() && i < 20; i++)                         {
                            double incPercent = (1 / webSites.Count()); 
                            if ((worker.CancellationPending == true))
                            {
                                eve.Cancel = true;
                                break;
                            }
                            else
                            {

                                string t = webSites[i];
                                                                if ((t.StartsWith("http://") == true) || (t.StartsWith("https://") == true)) // replace this with future FilterJunkLinks function
                                {
                                    for (int e = 0; e < csFiles.Count; e++)
                                    {
                                        if (csFiles[e].Contains(t))
                                        {
                                            already = true;

                                        }
                                    }

                                    if (!already)
                                    {
                                        actual_sites++;
                                        csFiles.AddRange(webCrawler(t, levels - 1,eve));
                                        this.Invoke(new MethodInvoker(delegate { Texts(richTextBox1, "Level Number " + levels + " " + t + Environment.NewLine, Color.Red); }));
                                        worker.ReportProgress(i * (int)incPercent);
  • 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-11T06:35:18+00:00Added an answer on June 11, 2026 at 6:35 am
    worker.ReportProgress(i * 10);
    

    Anytime you have i > 10 (That is, more than 10 pages), you are going over 100% in your progress bar.

    If you really wanted to do it by percentage, I would do something like this:

    double incPercent = (1 / webSites.Count())
    
    .
    .
    .
    .
    worker.ReportProgress(i * incPercent );
    

    As a side note, your variable names and spacing seem.. a little bit off

    Edit: Sorry, when performing a division of two numbers and you want the result to be in double, you have to make sure that either divisor or dividend is of type double. Otherwise, you are effectively performing int / int, which gives you an int back. As you probably know, int truncates your decimal points. This is the reason why you had zero in the calculation.

    Also, reportProgress method takes values from 0 to 100 so you have to multiply the end result by 100.

    Fix your code like this:

    double incPercent = (1 / (double)webSites.Count())
    
    .
    .
    .
    .
    worker.ReportProgress(i * incPercent * 100 );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this case, is it bad to subscribe to the proxy CloseCompleted event? public
In this case, I'm working on a project that involves a database of library
This case is a bit complex, I hope I will simplify it well. My
In this case the character is ^ . For example in the following format
In this case, the source of the text is from a winforms textbox. I'm
In this case, the Visual Studio designer generates a method which takes the parameter
Consider this case: public Class1 { public static final String ONE = ABC; public
Imagine this case, but with a lot more component buckets and a lot more
In this case, I've developed a CSS code for this web application ..and sometimes
I've just seen this case class in the Scala actors package: case class !

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.