0

I'm new to programming, I'm trying to use the webbrowser1 to increase the hit counter on a webpage, I can do this manually by clicking on the button to increase the hit counter, what I really wanted to do is make a for(i=0; i < 10 ; i++) statement to refresh the page 10 times, but then I use the statement like this it only increases the page by one, please see the code below, thanks in advance.

url: http://www.comptechdoc.org/independent/web/cgi/javamanual/javaihit.html

namespace click
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int i;

            for (i = 0; i < 10; i++)
            {
                webBrowser1.Refresh();
                Application.DoEvents();
            }
        }
    }
}

edit: thank you guys, for all your help and fast replys.

I've tryed the code from here: C# how to wait for a webpage to finish loading before continuing and it seems to work well.

private void button1_Click(object sender, EventArgs e)
{
    int i;

    for (i = 0; i < 10; i++)
    {
        webBrowser1.Navigate(url);

        while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
            Application.DoEvents();
    }
}
Community
  • 1
  • 1
user987642
  • 1
  • 1
  • 5

5 Answers5

0

The goal is not very good, cheating is bad:)

However try recreating webBrowser control.

dimko1
  • 872
  • 7
  • 15
0

Try putting this inside your loop:

 webBrowser1.Navigate(yourURL);
Icarus
  • 63,293
  • 14
  • 100
  • 115
0

Both links are very useful for you to solve your problem...

http://www.codeproject.com/KB/custom-controls/EasyHit.aspx

http://www.xdevsoftware.com/blog/post/Hit-Counter-for-ASPNET.aspx

sikender
  • 5,883
  • 7
  • 42
  • 80
0

You are refreshing the browser too fast - the hit is only counted when the server gets the request (which takes some time, and the previous request is canceled by next request by then).

namespace click
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int i;

            for (i = 0; i < 10; i++)
            {
                webBrowser1.Refresh();
                Thread.Sleep(1000);
                Application.DoEvents();
            }
        }
    }
}

Of course you should also consider moral side of what you are doing...

Matěj Zábský
  • 16,909
  • 15
  • 69
  • 114
-1

Your question is not clear. anyhow if you want to increase the counter value 10 times in 1 hit, you can do it by incrementing the existing value +10.

in the link you given you can use this code

counter += 10

instead of

++counter
SaQiB
  • 639
  • 8
  • 18
  • He wants to increase the website hit counter, not some variable. – svick Oct 10 '11 at 12:47
  • yes i know, that counter variable is actually incrementing the counter value in the example provided. so i just gave an example of how can he increment the value by 10 instead of 1... – SaQiB Oct 10 '11 at 13:10
  • Saqib, its about the amount of times he calls the method, the counter doenst have any other purpose than marking the bounds of the for loop... It doesn't make any difference if you use +10 or +1 trillion, because the server isn't getting the trillion requests.. – Rob Oct 10 '11 at 14:39