CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2011
    Posts
    22

    Wich Callback functions are connected?

    Hi

    If I connect
    thingi.Event += new EventHandler(CallBackFunction);
    how can I check wich callback functions are connected to the thingi.Event?

    Now I just try to remove every connection and then establish the new one. Is there a better way?


    GMarco

  2. #2
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Wich Callback functions are connected?

    As far as I know, the only way of keeping track of your eventhandlers is by adding them to a collection when you assign them.

    something like:

    Code:
    EventHandler eh = new EventHandler(MyMethod);
    myObject.Event += eh;
    myEvents.Add(eh);
    Then you'll have a list of eventhandlers that you can check - you would need to do this for each object though.
    It's not a bug, it's a feature!

  3. #3
    Join Date
    May 2007
    Posts
    1,546

    Re: Wich Callback functions are connected?

    Instead of having:
    Code:
    public event EventHandler Foo;
    just do:

    Code:
    EventHandler foo;
    public event EventHandler Foo {
        add { foo += value; }
        remove { foo -= value; }
    }
    Then you can iterate over 'foo' and remove eventhandlers you don't need, set it to null to clear everything, or whatever it is you want to do. There are probably better ways of doing it though.
    www.monotorrent.com For all your .NET bittorrent needs

    NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.

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

Featured