473,385 Members | 1,570 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,385 software developers and data experts.

WithEvents ???

Is there any additional overhead for declaring a variable using the
WithEvents keyword even if none of the events are being handled?
Nov 20 '05 #1
6 2885
I would imagine yes, but I can't give specifics.
<mr***@exhibitworks.com> wrote in message
news:OY****************@TK2MSFTNGP12.phx.gbl...
Is there any additional overhead for declaring a variable using the
WithEvents keyword even if none of the events are being handled?

Nov 20 '05 #2
* <mr***@exhibitworks.com> scripsit:
Is there any additional overhead for declaring a variable using the
WithEvents keyword even if none of the events are being handled?


What do you mean by "overhead"? Maybe a little overhead, but you don't
need to care about that.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Is it possible that its just a keyword for the visual basic compiler that
connects an object's events to some handlers? C# and Visual Basic both
compile to IL, if it did have overhead (other than compilation) it would
have to show up there.
"Scott M." <s-***@BADSPAMsnet.net> wrote in message
news:O9**************@TK2MSFTNGP11.phx.gbl...
I would imagine yes, but I can't give specifics.
<mr***@exhibitworks.com> wrote in message
news:OY****************@TK2MSFTNGP12.phx.gbl...
Is there any additional overhead for declaring a variable using the
WithEvents keyword even if none of the events are being handled?


Nov 20 '05 #4
I am pondering here but would imagine that there is no overhead because I
would again imagine that the MSIL compiler is very efficient and would
realize that there are no eventsinks for the object and hence remove and
event handling code.

A question for you is why would you declare an object withEvents if you do
not plan on using them?
<mr***@exhibitworks.com> wrote in message
news:OY****************@TK2MSFTNGP12.phx.gbl...
Is there any additional overhead for declaring a variable using the
WithEvents keyword even if none of the events are being handled?

Nov 20 '05 #5
Hi NoOne,

You are correct, WithEvents (in conjuction with the Handles clause) removes
the arduous task of AddHandler and RemoveHandler on all events for any
controls you make.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
"NoOne" <No@Where.com> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
Is it possible that its just a keyword for the visual basic compiler that
connects an object's events to some handlers? C# and Visual Basic both
compile to IL, if it did have overhead (other than compilation) it would
have to show up there.
"Scott M." <s-***@BADSPAMsnet.net> wrote in message
news:O9**************@TK2MSFTNGP11.phx.gbl...
I would imagine yes, but I can't give specifics.
<mr***@exhibitworks.com> wrote in message
news:OY****************@TK2MSFTNGP12.phx.gbl...
Is there any additional overhead for declaring a variable using the
WithEvents keyword even if none of the events are being handled?



Nov 20 '05 #6
<mr***@exhibitworks.com> schrieb
Is there any additional overhead for declaring a variable using
the WithEvents keyword even if none of the events are being
handled?


As it's already been mentioned, Withevents does Addhandler/removehandler
internally for you.

Variables declared with Withevents are actually properties.

Writing

private withevents cmd as button

sub cmd_click(...) handles cmd.Click
end sub
is exactly the same as

private _cmd as button

private property cmd() as button
get
return _cmd
end get
set (byval value as button)
if not _cmd is nothing then
removehandler _cmd.click, addressof cmd_click
end if
_cmd = value
if not _cmd is nothing then
addhandler _cmd.click, addressof cmd_click
end if
end set
end property
The more "Handles" procedures, the more removehandler/addhandler statements
are created.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


Nov 20 '05 #7

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

Similar topics

7
by: Jonas | last post by:
This works fine in Win XP but does not work at all in Win 98. Private WithEvents objIExplorer As InternetExplorer I have to do it like this to get it to work in Win 98 Dim objIExplorer As...
2
by: Jakob Bengtsson | last post by:
Hi, I have a form (which cannot be serialized). In the form's code I declare an object like this (never mind the object nor class name, it's for illustration only): Private WithEvents...
5
by: Bradley Grant | last post by:
I am trying to write a program to access a device through USB port, there is some Visual Basic program examples that work with the device, but I am trying to write a program using C#, no luck yet,...
4
by: Tee | last post by:
Hi, I am converting a code from VB to C#. in VB, it's Private WithEvents MyButton As Button what's the code in C# ? I can't get the replacement for the "WithEvents" in C#.
2
by: Peter | last post by:
Hello, Thanks for reviewing my question. I am following KB article about creating a custom control and its source code is in VB. I got to a part where I have the following: Private...
0
by: Steve | last post by:
Hello, I have been experimenting/learning to use aspx with and without VS2003. In VS 2003 I created a simple webform/application which contains a listbox and a label. I populate the listbox...
4
by: Shapper | last post by:
Hello, I have an aspx.vb page with this code: Public Class WebForm1 Inherits System.Web.UI.Page Protected WithEvents Menu1 As MenuControl.Web.UI.Menu ... If I have my code in the aspx...
8
by: Bob Day | last post by:
Using VS 2003, VB.NET, MSDE If an event is raised in a class that was NOT instantiated with the WithEvents key word, is that event effectively ignored? Or, another way to phrase the question,...
8
by: DareDevil | last post by:
Class MyClas Friend ReadOnly WithEvents MyObject as AnotherClas .. End Clas I have a VB.NET class that has a readonly object (i.e. It can only be assigned in the constructor). This enables me...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...

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.