« C# changes from 1.1 to 2.0 | Main | Experiences with Whidbey Beta 1 »

Whidbey, Visual Basic event handlers

In Visual Basic, event handlers are defined and registered declaratively in one step by adding a “Handles <instance>.<event>” clause to a Sub or Function declaration whose signature matches the event’s delegate.

Because the declarative style is used, as opposed to C#’s imperative style (event += new <delegate>), there is no control over the lifetime of the event registration. This can require additional code and effort when the lifetime of the event source extends beyond the lifetime of a resource required by the handler.

A second limitation of Visual Basic event handler support appears to be that a generic delegate defined in C# can not be used to define an event if you want Visual Basic clients to be able to bind to it.

 

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)