Craig Gemmill's Blog

There is nothing more secure than an educated user!

March 2004 - Posts

Visual Studio 6.0 Service Pack 6

Just stumbled across it while looking for updates, download below.
http://msdn.microsoft.com/vstudio/downloads/updates/sp/vs6/sp6/download/default.aspx

TVB.NPL

I’ve seen a bit of talk on the blogs about Paul Vicks new book, ”The Visual Basic .NET Programming Language”, so when I came across it at the book store I figured I would take a peek. I opened up a random part of the book, to a chapter titled “Delegates and Event Implementation”. There was nothing particularly new to me in this section; but by the way it was written, and the content provided, it actually made me feel more confident in my vb.net knowledge just after a couple minutes of reading. It was very much more of a “why and how it works” description, then just a quick overview and example like many other books. So I bought it.

Coming from a mostly <=VB6 background, there are still several OOP techniques that I have been trying to perfect, and this book certainly helped me get to the next level. And it’s not that the book is written for people with advance knowledge of vb.net, it’s just that it has the right information, which makes it not only a great book for beginners, but also for those that are already deep in the language and still looking to have some basic questions answered.

Also, it’s rare to find a programming book that reads as smoothly, and has as easy-on-the-eyes text as this book does.

Good job Paul, highly recommended.

The Shield...

The Shield on FX Network returns this evening with the premiere of season 3 at 10:00pm (Eastern).

“This intense police drama set in Los Angeles stars a riveting Michael Chiklis (The Commish) as a corrupt detective who heads up the precinct strike team. A force to be reckoned with, he manages to involve the entire team in his twisted schemes and manipulative machinations.

If you thought NYPD Blue was dark and gritty, wait until you see The Shield. The cast includes CCH Pounder and Reed Diamond.“ - Here

Some people love the show, some hate it, but either way, if you've never seen it before, it's not the best show for kids to watch.

MDI Tool Windows

[vb.net] I have been working on a couple different designs for handling the communication between “documents“ and their associated tool windows, and this particular project implements what I think to be the best method. The vb.net project can be downloaded from here.

Asynchronous Event Delegation

[vb.net]I was playing around with delegates today and came up with a quick example of how to fire events using delegates in an asynchronous manner (fire an event and continue processing).

Revised Code (Original at bottom):

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
'JUST ADD A STANDARD BUTTON TO YOUR FORM
#End
Region
'
'Create instance of class
'
Friend oDelClass As New DelClass

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      '
      'Add a handler for the event. Could also be done WithEvents .
      '
      AddHandler oDelClass.DoneProcessing, AddressOf dosomething
End
Sub

Public
Sub dosomething(ByVal sender As Object, ByVal e As System.EventArgs)
      MsgBox("I've been shown from a new thread pool thread!")
End
Sub

Private
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      '
      'Call procedure that will raise an event when done.
      '
      oDelClass.ProcessSomething()
End
Sub

End
Class

Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
'JUST ADD A STANDARD BUTTON TO YOUR FORM
#End
Region
'
'Create instance of class
'
Friend oDelClass As New DelClass

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      '
      'Add a handler for the event. Could also be done WithEvents .
      '
      AddHandler oDelClass.DoneProcessing, AddressOf dosomething
End
Sub

Public
Sub dosomething(ByVal sender As Object, ByVal e As System.EventArgs)
      MsgBox("I've been shown from a new thread pool thread!")
End
Sub

Private
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      '
      'Call procedure that will raise an event when done.
      '
      oDelClass.ProcessSomething()
End
Sub

End
Class

Public Class DelClass
'
'Delegate (function pointer)
'
Friend Delegate Sub MyEventHandler(ByVal sender As Object, ByVal e As System.EventArgs)
'
'Instance of the function pointer that points to OnDoneProcessing.
'
Private MyEventInvoker As New MyEventHandler(AddressOf OnDoneProcessing)
'
'Event declaration where MyEventHandler is simply an interface.
'Could be: Friend MyEvent(byval sender as object, byval e as system.eventargs)
'
Friend Event DoneProcessing As MyEventHandler
'
'Overidable event calling procedure.. standard .NET event design
'
Friend Overridable Sub OnDoneProcessing(ByVal sender As Object, ByVal e As System.EventArgs)
      '
      'If OnDoneProcessing was called using BeginInvoke, then you are already running in a thread
      'pool thread parallel to the caller thread (async).
      '
      'Fire the event
      '
      RaiseEvent DoneProcessing(sender, e)
End
Sub

Friend Sub ProcessSomething()
      '
      'Perform some processing that in return raises an event...
      '
      'Calls OnDoneProcessing, which raises the event, in a new thread.
      '
      Call MyEventInvoker.BeginInvoke(New Object, New System.EventArgs, Nothing, Nothing)
      '
      'You could also use a function, then use EndInvoke, or a callback, to get the return.
      'That is beyond the needs of this example, but here is a link:
      'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconasynchronousdelegatesprogrammingsample.asp?frame=true
      '
End
Sub

End
Class

Class DelClass
'
'Delegate (function pointer)
'
Friend Delegate Sub MyEventHandler(ByVal sender As Object, ByVal e As System.EventArgs)
'
'Instance of the function pointer that points to OnDoneProcessing.
'
Private MyEventInvoker As New MyEventHandler(AddressOf OnDoneProcessing)
'
'Event declaration where MyEventHandler is simply an interface.
'Could be: Friend MyEvent(byval sender as object, byval e as system.eventargs)
'
Friend Event DoneProcessing As MyEventHandler
'
'Overidable event calling procedure.. standard .NET event design
'
Friend Overridable Sub OnDoneProcessing(ByVal sender As Object, ByVal e As System.EventArgs)
      '
      'If OnDoneProcessing was called using BeginInvoke, then you are already running in a thread
      'pool thread parallel to the caller thread (async).
      '
      'Fire the event
      '
      RaiseEvent DoneProcessing(sender, e)
End
Sub

Friend Sub ProcessSomething()
      '
      'Perform some processing that in return raises an event...
      '
      'Calls OnDoneProcessing, which raises the event, in a new thread.
      '
      Call MyEventInvoker.BeginInvoke(New Object, New System.EventArgs, Nothing, Nothing)
      '
      'You could also use a function, then use EndInvoke, or a callback, to get the return.
      'That is beyond the needs of this example, but here is a link:
      'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconasynchronousdelegatesprogrammingsample.asp?frame=true
      '
End
Sub

End
Class

James made an excellent blog that inherits from a button and mirrors the standard click event with an ASync version. This design is very flexible, and suitable for use with any inheritable class that has events.

More Posts