Results 1 to 6 of 6

Thread: Is there a way to tell where an event was raised from?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    258

    Question Is there a way to tell where an event was raised from?

    I've got an event that's firing more times than I thought it should fire. Is there any way to tell where an event was raised from?

    The event is DataContextChanged for a ComboBox. All I need is basic data on what caused the event to fire... any way to do it?

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Is there a way to tell where an event was raised from?

    Yes, the sender argument of all event handlers keeps a reference to the object that raised the event.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    258

    Re: Is there a way to tell where an event was raised from?

    Yeah, I checked that first. They all point back to the combo box itself... and since I know for a fact that at least one of the events is fired via code, manually setting the SelectedIndex value... well, that means that it doesn't really differentiate between code and user action.

  4. #4
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: Is there a way to tell where an event was raised from?

    Could you not set a breakpoint on the event handler and, when hit, examine the call stack? I think that any code that is causing the event will show up that way.

  5. #5
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Is there a way to tell where an event was raised from?

    You you've solved the problem I take it?

    [EDIT]

    Inferred posted while I was making mine.

    My question was in response to your last post:-
    Yeah, I checked that first. They all point back to the combo box itself... and since I know for a fact that at least one of the events is fired via code, manually setting the SelectedIndex value... well, that means that it doesn't really differentiate between code and user action.
    I'm not certain what you are trying to say here.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Is there a way to tell where an event was raised from?

    There isn't necessarily a way to determine what caused the event to trigger, just who triggered it. Examining the call stack at the time of the event can tell you some things, but it may not tell you what you want to know. MSDN might also give you some information as to what actions can trigger certain events, but aside from that you can probably work it out just by testing things.
    My usual boring signature: Nothing

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width