Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public bool IsEventHandlerRegistered(Delegate prospectiveHandler)
- {
- if ( this.EventHandler != null )
- {
- foreach ( Delegate existingHandler in this.EventHandler.GetInvocationList() )
- {
- if ( existingHandler == prospectiveHandler )
- {
- return true;
- }
- }
- }
- return false;
- }
- myClass.MyEvent -= MyHandler;
- myClass.MyEvent += MyHandler;
- public class MyClass
- {
- event Action MyEvent;
- }
- ...
- MyClass myClass = new MyClass();
- myClass.MyEvent += SomeFunction;
- ...
- Action[] handlers = myClass.MyEvent.GetInvocationList(); //this will be an array of 1 in this example
- Console.WriteLine(handlers[0].Method.Name);//prints the name of the method
- try
- {
- control_name.Click -= event_Click;
- main_browser.Document.Click += Document_Click;
- }
- catch(Exception exce)
- {
- main_browser.Document.Click += Document_Click;
- }
- EventHandler.GetInvocationList().Length > 0
- bool alreadyAdded = false;
- if(alreadyAdded)
- {
- myClass.MyEvent += MyHandler;
- alreadyAdded = true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement