locked
Following code runs twice not sure why though? RRS feed

  • Question

  • I have the following code here and it runs twice, it should only run once.

     private void oDoc_MouseUp(object sender, HtmlElementEventArgs e)
            {
                if (e.MouseButtonsPressed == MouseButtons.Middle)
                {
                    if (oElement.TagName == "A")
                    {
                        frminvbrowser fbrowser = new frminvbrowser(_Ibrowser, _DLHistory, _AdditionalSettings);
                        IbrowserManager.AddTab(_Ibrowser.tc, fbrowser, this.wb.StatusText);
                    }
                }
            }
    fbrowser is a form, and the addtab gets the tabcontrol, then the form to add, then the status text from the webbrowser control. I dont see a loop here? 
    OMG, its Joe Ginley!
    Tuesday, August 11, 2009 2:00 AM

Answers

  • Well when the document load is completed i do have this code in there:

    oDoc.MouseUp += oDoc_MouseUp;

    I have that line of code added under the webbrowser completed event.


    OMG, its Joe Ginley!

    Is that one place or two that you are describing.  It only needs to appear once, in the Form_Load event handler.

    Mark the best replies as answers. "Fooling computers since 1971."
    • Marked as answer by JoeGinley Tuesday, August 11, 2009 6:03 PM
    Tuesday, August 11, 2009 5:50 PM

All replies

  • The event apparently is being subscribed to twice. 
    It usually happens when you connect it up with the Form Designer, and again by writing it up in your code.
    But, I don't think MouseUp is an event that the Designer will connect up for you.

    Try doing a search of all files in the project for the method name text, "oDoc_MouseUp" or just "MouseUp".

    Or just right-click on the method name, and select "Find All References".

    Rudedog   =8^D

    Mark the best replies as answers. "Fooling computers since 1971."
    Tuesday, August 11, 2009 2:01 PM
  • Well when the document load is completed i do have this code in there:

    oDoc.MouseUp += oDoc_MouseUp;

    I have that line of code added under the webbrowser completed event.


    OMG, its Joe Ginley!
    Tuesday, August 11, 2009 4:56 PM
  • As Rudedog mentioned, if you wrote the code and also hooked it up using the UI, this same code may also be in the .designer file.

    Hope this helps.


    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Tuesday, August 11, 2009 5:15 PM
  • Right-click on the method name, and select "Find All References".

    You should get only two results. 
    The actual method, and the line of code where you add the method to the event's Invocation List. 
    That means where you subscribe to the event.

    You do not want to subscribe, or add the event to the list, twice. 
    Every entry in the Invocation List of target methods gets called, duplicates and all.
    Mark the best replies as answers. "Fooling computers since 1971."
    Tuesday, August 11, 2009 5:48 PM
  • Well when the document load is completed i do have this code in there:

    oDoc.MouseUp += oDoc_MouseUp;

    I have that line of code added under the webbrowser completed event.


    OMG, its Joe Ginley!

    Is that one place or two that you are describing.  It only needs to appear once, in the Form_Load event handler.

    Mark the best replies as answers. "Fooling computers since 1971."
    • Marked as answer by JoeGinley Tuesday, August 11, 2009 6:03 PM
    Tuesday, August 11, 2009 5:50 PM
  • that is only one place, if it dont need to be there ill try it in just the load event.
    OMG, its Joe Ginley!
    Tuesday, August 11, 2009 6:01 PM
  • Thank you, the problem is solved, i moved the event into the load event, under the document completed it adds the handler each time i complete loading the document.
    OMG, its Joe Ginley!
    Tuesday, August 11, 2009 6:03 PM