event names

Underling

New member
Joined
May 27, 2010
Messages
3
Programming Experience
Beginner
Hi all,

I'm using an older version of .net (1.1) and I was looking for an implementation of BackgroundWorker that I could use with it. I found one here (TALLEY OURO BLOG: Custom Backgroundworker with VB), but I have trouble understanding one part of it.

The example includes this declaration

VB.NET:
Public Event DoWork As DoWorkEventHandler

with a delegate handler and argument class. My problem is that the code contains the following line

VB.NET:
If Not (DoWorkEvent Is Nothing) Then

Nowhere else in the code does the exact text
DoWorkEvent
appear, but the compiler accepts it quite happily. Can you tell me whether this name is created automatically, and could you point me towards an explanation in the .net help?

Thanks.
 
When an event is declared in VB the compiler generates several things, among them the handler delegate (if none is specified) and a hidden field that hold the handler delegate instance (the eventnameEvent field). Normally in VB it is not accessed from client code, but this code use it to BeginInvoke calls to each worker handler, as a simplification to using a custom event - or a plain delegate parameter. There is extensive documentation about events and the delegate model in help: Events in Visual Basic
 
Thanks JohnH, as you recommended I've looked through the help and I can't find this described anywhere. Would you be able to give me a hint as to where to look? I hope I'm not being too thick...
 
If you want it spelled out I recommend you study the basics of events in C#, here these things must be defined explicitly. VB does events in the simplistic way that is described in the help topics I linked to (Event keyword, WithEvents-Handles/AddHandler etc) and the underlying event wire-ups is hidden - but you will see described how to define a Custom Event (for example in the last two How-To help topics and in help topic for Event statement), in addition to general description of delegates (for example follow link to 'Delegates in Visual Basic' and further to 'Delegates and the AddressOf Operator' article.)
 
Back
Top