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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:09:01+00:00 2026-06-10T22:09:01+00:00

I have a problem with two of my EventHandlers, they work the same, so

  • 0

I have a problem with two of my EventHandlers, they work the same, so here is one:

    private void Form1_Load(object sender, EventArgs e)
    {
        webBrowserWebsite.Url = new System.Uri(textBoxURL.Text, System.UriKind.Absolute);
        webBrowserWebsite.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowserWebsite_DocumentCompleted);
    }


    void webBrowserWebsite_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
            StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\CurrentData.wfd");
            sw.Write(webBrowserWebsite.Document.Body.InnerText);
            sw.Close();
    }

The problem is, that the EventHandler fires multiple times, it doesn’t stop!
Why is it doing this?
Thanks in advance

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

    The code that you have written won’t compile (your StreamWriter in your EventHandler isn’t assigned to anything) and without more context as to how you are calling this, it is difficult to say for certain.

    But the most likely reason is you are calling Form1_Load multiple times, but using the same webBrowserWebsite object. Each time the form loads, you are adding a new Event Handler. And since you aren’t showing any code showing where you removing the event handler, I’m guessing it fires once for each time you call Form_Load.

    Depending on your design, you are better off adding the event handler in the constructor so it is only added once regardless of the number of times you load the form.

    public Form1()
    {
        webBrowserWebsite.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowserWebsite_DocumentCompleted);
    }
    
    private void Form1_Load(object sender, EventArgs e)
    {
        webBrowserWebsite.Url = new System.Uri(textBoxURL.Text, System.UriKind.Absolute);
    }
    

    Or remove the event handler in the event handler:

    void webBrowserWebsite_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\CurrentData.wfd");
        sw.Write(webBrowserWebsite.Document.Body.InnerText);
        sw.Close();
        webBrowserWebsite.DocumentCompleted -= webBrowserWebsite_DocumentCompleted;
    }
    

    Also, since StreamWriter implements IDisposible, you should be putting it inside of a using block or at least calling sw.Dispose() at the end of the method

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

Sidebar

Related Questions

I have a problem with two Textviews on the same height in a RelativeLayout
Problem: I have two array where one produce a category and the second produce
I have a problem with IE causing two errors: 1. Object doesn't support this
I have problem when I tried to update two tables in one Store Procedure
I Have two problem in this Case : I want to pass a JSON
I have had this problem w/ two seperate WYSWYG editors in my rails application
I have an strange problem using two borders. I use them to display video
Hello I have problem to put together animations of two separate objects to second
I have a design problem: I have two threads, a heartbeat/control thread and a
I have a problem in association between two classes, so i have a 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.