views:

9

answers:

1

How to know that DataTable is already subscribed to OnRowChanged or OnColumnChanged events ? I am facing a issue with many notifications in my app ? so I wanted to put a check and want to subscribe table only once ??

A: 

Outside of the declaring class it is deliberately tricky to see what is subscribed, since that is generally not something you need to know.

Depending on the scenario, either get very good at tracking when you subscribe, or simply unsubscribe first (which does nothing if you aren't subscribed):

foo.OnSomeEvent -= SomeHandler;
foo.OnSomeEvent += SomeHandler;

As long as the handler and target-instance (for non-static handlers) is the same this will:

  • if subscribed, the net result is that you are still subscribed afterwards
  • if not subscribed, the net result is that you end up subscribed
Marc Gravell