WithEvents ???

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there any additional overhead for declaring a variable using the
WithEvents keyword even if none of the events are being handled?
 
* said:
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.
 
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.
 
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?
 
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
 
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.
 
Back
Top