Convert (If (SomeEvent != null)) into VB

As I said yesterday, I translated 3 labs on official WF HOLs from C# to VB2005. Today I start the lab04, I found out that there are some code that I cannot find a way to make it work in VB. So I start searching and found the following result in http://www.codeproject.com/vb/net/backgroundworker.asp . Following what he said and the code now is working.


==========================================================================================


This was not without its quirks.


The best practice for raising events tells us that we should always test that the event is not null before raising the event. That is to say, the event must have handlers. All the articles then give a code sample something like this:

         if(SomeEvent != null)
         {
            SomeEvent(this, args);
         }

The C# implementations of BackgroundWorker both used this standard. But how do I do that in VB.NET? If you try the statement SomeEvent != Nothing, you get the error: ‘Public Event SomeEvent(sender As Object, e As System.EventArgs)’ is an event, and cannot be called directly. Use a ‘RaiseEvent’ statement to raise an event. Not very useful!


It turns out that in VB.NET, to get at the delegate derived object to test if it is Nothing, you just add “Event” to the end of the event name. Don’t go looking for it in intellisense though, because it won’t be there! The resulting VB.NET code is:

         if Not SomeEventEvent is Nothing Then
            SomeEventEvent(Me, args)
         End If

Why have I used SomeEventEvent(Me, args) instead of RaiseEvent SomeEvent(Me, args)?


The default method of a delegate is the Invoke method, and RaiseEvent in VB.NET just calls this method on the delegate, and it makes my code less language specific. Personal preference really.


==========================================================================================

Windows Workflow Foundation(WF) Hands-On Lab01 to Lab03 in VB2005

If you are interesting in Windows Workflow Foundation(WF), you should found only C# hands-On Lab. A good news to you, I tried to translated them into VB2005, and it was tested by WF Team and now, you may download them from the following link, the full story are here…


I have 2 entries on the translation of WF, one is including Lab01, while another one is including Lab01-Lab03, they are both top 5 download in http://www.netfx3.com/


===========================================================


http://blogs.msdn.com/pandrew/archive/2006/12/02/Windows-Workflow-Foundation-and-Visual-Basic-.NET.aspx
The Windows Workflow Foundation (WF) runtime supports all CLS compliant programming languages. The Visual Studio 2005 extensions for WF are only provided for C# and Visual Basic .NET. It’s easy to find C# samples to get started. Here’s some pointers to samples for getting started with Windows Workflow Foundation in Visual Basic .NET.


Hands on Labs in VB.NETKen Lin has kindly translated these introductory WF HOLs to VB.NET


http://wf.netfx3.com/files/folders/documentation/entry7167.aspx (Lab01)


http://wf.netfx3.com/files/folders/documentation/entry7553.aspx (Lab01-Lab03)
.