[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

check if an event is hooked?

Posted on 2008-10-07
6
Medium Priority
?
787 Views
Last Modified: 2013-11-26
Hi experts

I have a BindingSource which has the event CurrentChanged.

Now have to hook/unhook this event dynamically in my code. This alone wouldn't be a problem.
But how can I check if the CurrentChanged event is hooked up?

I tried

if(this.MyBindingSource.CurrentChanged == null)
{

}

but this gives an error which says that I can use CurrentChanged only with += or -=
I'm using .NET 2.0, VS2008, WinForms

Thanks
0
Comment
Question by:Arikael
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 13

Expert Comment

by:crazyman
ID: 22658448
Not usre exactly but take a look at

this.Events[eventname].GetInvocationList().Length
0
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22658451
Sample events:

this.Init += new EventHandler(Default3_Init); // to add
this.Init -= new EventHandler(Default3_Init); // to remove
0
 
LVL 13

Expert Comment

by:crazyman
ID: 22658456
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22658460
you can further check
if (this.Init != null) { .. event is hooked }  else { event is not hooked .. }
0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 2000 total points
ID: 22658514
I tried your code and got the same exception (not with binding source but with normal button control)
i am assuming that the inbuilt microsoft controls dont allow you from checking whether the event has been subscribed to or not

in this case i will recommend you to use a variable holding how many events have been hooked to and when ever a new event is hooked the value will be incremented and vice versa
0
 
LVL 3

Author Comment

by:Arikael
ID: 22658563
@crazyman

your code gives me the same exception as noted in my question.
it seems that you can't check whether the event has been subscribed to or not (see ragi0017's post).

Until now I just "unhooked" my event before I hooked it.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question