Determine if an event has been attached to yet

前端 未结 4 1133
悲哀的现实
悲哀的现实 2021-01-12 07:12

I have two objects - one that contains some code with will fire an event, and one that contains the handler for that event. I can\'t \"AddHandler\" in the Load of the first

4条回答
  •  清酒与你
    2021-01-12 07:22

    According to the responses here: http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/9ec8ff1c-eb9b-4cb3-8960-9cd4b25434f2 (which seem to work according to my testing), a check for existing event handlers is done upon calling RaiseEvent. If you do not want to raise an event and just need to check to see if any handlers are attached, you can check the value of a hidden variable called Event like:

    Public Event Foo As ActionFoo
    
    If FooEvent IsNot Nothing Then...
    

提交回复
热议问题