Application events in VB2005 (by yag)

One interesting thing about VB2005 is that it ships with a lightweight application framework that provides a number of interesting events. One of those is NetworkAvailabilityChanged. Strangely enough, it fires whenever you go from online to offline and back again.

To access the framework, go to MyProject in Solution Explorer and double-click, bringing up the project properties. Click on "View Code" and you'll have access to a partial class that works with your application.

As a test, I dropped a label on a form and added the following to the application class:

Private Sub MyApplication_NetworkAvailabilityChanged(ByVal sender As Object, _
   ByVal e As Microsoft.VisualBasic.MyServices.NetworkAvailableEventArgs) Handles Me.NetworkAvailabilityChanged

   If e.IsNetworkAvailable Then
      form1.label1.ForeColor = Color.Green
form1.label1.Text = "Online"
   Else
      form1.label1.ForeColor = Color.Red
form1.label1.Text = "Offline"
   End If

End Sub

One of the things I love about VB2005 is the fact that it's so easy to get at these types of events.

UPDATE: As I was going through my blogs, I came across this entry showing how to hook the same event in C#. A bit more code, but still cool...