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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:58:25+00:00 2026-05-26T13:58:25+00:00

I got a VERY weird problem happening with ALL my DocumentCompleteEventHandlers. Say I have

  • 0

I got a VERY weird problem happening with ALL my DocumentCompleteEventHandlers.

Say I have a very simple handler:

void Download_Complete_Handler(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            string link = webBrowser1.Url.ToString();
            Regex rgx = new Regex("(^https://mysite.com/)");
            if (rgx.IsMatch(link)) // have made it this way so that I don't remove the handler for every page. Pretty handy.
            {
                string name = choosename(); // my custom function to create new name
                string surname = choosesurname(); // my custom function to create new surname
                Random rand = new Random();

                webBrowser1.Document.GetElementById("id").Focus();
                SendKeys.SendWait(name + "." + surname + rand.Next(0, 9999).ToString());

                name = "";
                surname = "";
            }
        }

And I call this handler in following function which is called on button click:

void myfunction()
{
  try
  {
    webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Download_Complete_Handler);
    webBrowser1.Navigate("mysite.com");
  }
  catch(Exception ex)
  {
    log(ex);// my custom log function
  }
}

Now, when I first launch the program, and I click the button to trigger the handler, all works OK: Webbrowser is navigated, once page is loaded – the needed field is filled in.
Now let’s say, I click the same button once again, so that all process starts all over again. This time the handler is called twice: once page is loaded, the field is filled two times. Third click will trigger the handler three times, etc.

Do you know what I’m doing wrong?

  • 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-05-26T13:58:25+00:00Added an answer on May 26, 2026 at 1:58 pm

    Yes – you’re adding a new handler every time the button is clicked. The old handlers aren’t removed – they’ll stick around forever (unless you remove them explicitly, of course).

    Add the handler once, and then just perform navigation in the button click.

    As an aside, it’s generally not a good idea to create multiple instances of Random like this. See my article on the topic.

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

Sidebar

Related Questions

I have got very big problem because I would like to get more information
I've got a very weird and unexpected problem. empty() is returning TRUE on a
I got this very weird problem...and it's very important to my...dead line is close...and
I've got a very weird issue. I've got this Procedure object that contains two
I've got very weird problem in my current project. The #head div looks like
Today I got a very weird problem which I was able to solve, but
I've got a very weird one. I have about a dozen PC's in our
I got a weird problem. I have a program that (does many things but
I've got a weird maths/rounding problem in Javascript. The snippet below is a very
I've got some very weird behavior in my PHP code. I don't know if

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.