473,378 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Counting the number of Event handlers

Hello!
Is it possible to find how many event handlers an event has at runtime? How
about finding whether or not an event has event handlers? In C# you can
compare the event with null to check if it has event handlers, but I can't
find the equivalent in VB.
Thanks
Amit
Nov 21 '05 #1
5 3832
"Amit" <re***********@hotmail.com> schrieb:
Is it possible to find how many event handlers an event has at runtime?
How
about finding whether or not an event has event handlers? In C# you can
compare the event with null to check if it has event handlers, but I can't
find the equivalent in VB.


In VB.NET you don't need to compare to 'null', simply use 'RaiseEvent' to
raise the event.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Oe**************@TK2MSFTNGP09.phx.gbl...
"Amit" <re***********@hotmail.com> schrieb:
Is it possible to find how many event handlers an event has at runtime?
How
about finding whether or not an event has event handlers? In C# you can
compare the event with null to check if it has event handlers, but I can't find the equivalent in VB.


In VB.NET you don't need to compare to 'null', simply use 'RaiseEvent' to
raise the event.


That is fine, but is there a way to find out if there are event handlers?
For example if there's something I need to do only if there are event
handlers before I raise the event..
Thanks
Amit
Nov 21 '05 #3
"Amit" <re***********@hotmail.com> schrieb:
That is fine, but is there a way to find out if there are event handlers?


<URL:http://dotnet.mvps.org/dotnet/code/codingtechnique/#EventHandlerCount>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #4

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Om**************@TK2MSFTNGP14.phx.gbl...
"Amit" <re***********@hotmail.com> schrieb:
That is fine, but is there a way to find out if there are event
handlers?
<URL:http://dotnet.mvps.org/dotnet/code/codingtechnique/#EventHandlerCount>


I don't think this sample code is syntactically correct. It has this
snippet:
If FooEvent Is Nothing Then
Return 0
Else
Return FooEvent.GetInvocationList().Length
End If

but FooEvent is never declared. Perhaps the author meant to say Foo, which
is declared as an event but in that case I will not be able to call
GetInvocationList method because it is not static.
Thanks
Amit
Nov 21 '05 #5
Amit,
| but FooEvent is never declared. Perhaps the author meant to say Foo, which
| is declared as an event but in that case I will not be able to call
| GetInvocationList method because it is not static.
Ah! There's the rub!

FooEvent is declared by the compiler, when the compiler sees the Event Foo
declaration.

In other words, its an implementation detail of how the Event keyword is
implemented.

You can use ILDASM to see the defination of FooEvent.

Try it & see, the code will work as demonstrated.

Hope this helps
Jay

"Amit" <re***********@hotmail.com> wrote in message
news:O2**************@TK2MSFTNGP10.phx.gbl...
|
| "Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
| news:Om**************@TK2MSFTNGP14.phx.gbl...
| > "Amit" <re***********@hotmail.com> schrieb:
| > > That is fine, but is there a way to find out if there are event
| handlers?
| >
| >
|
<URL:http://dotnet.mvps.org/dotnet/code/codingtechnique/#EventHandlerCount>
| >
|
| I don't think this sample code is syntactically correct. It has this
| snippet:
| If FooEvent Is Nothing Then
| Return 0
| Else
| Return FooEvent.GetInvocationList().Length
| End If
|
| but FooEvent is never declared. Perhaps the author meant to say Foo, which
| is declared as an event but in that case I will not be able to call
| GetInvocationList method because it is not static.
| Thanks
| Amit
|
|
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
8
by: Dennis C. Drumm | last post by:
I have a class derived from a SortedList called SystemList that contains a list of objects indexed with a string value. The definition of the objects contained in the SortedList have a boolean...
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
1
by: Jerry | last post by:
We have a 10-question quiz for kids, each question being a yes or no answer using radio selections. I'd like to keep a current total of yes's and no's at the bottom of the quiz (if the user selects...
6
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the...
16
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some...
14
by: Hamed | last post by:
Hello It seems that I should implement ICloneable to implement my own clone object. the critical point for me is to make a control object based on another control object that all of its event...
6
by: Jake K | last post by:
Where is the best place to define event handlers? I need to define event handlers for a COM object referenced in my project and am doing so in the fowm load. Is this the best place?
6
by: Tony Johansson | last post by:
Hello! I know it's possible to have several event handler for a single event but I can't see any point using several event handler for this. I'm probably wrong so can anybody tell me what...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.