|
-
September 19th, 2011, 06:14 AM
#1
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
-
September 19th, 2011, 07:23 AM
#2
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!
-
September 19th, 2011, 11:30 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|