Handling an Application Event in another application

17 Sep

I was working on a Console application that read SQL Database connection details from a configuration file then send these details to another application (Let us call it the Update Application) which will go through the records of a table to update them using a For Loop, I wanted to show a status message on the Console screen for each record.


In the Update Application (VB.NET) I defined a Public event to handle the status message


Public Event Message(ByVal sMessage As String)

In the update function I raised this event with the required message

For Each dbRow In DataSet.Tables(“DataTables”).Rows


      RaiseEvent Message(“Start Processing record of ID “  & dbRow (“ID”).ToString())

                    ‘Do the Update Here                          

      RaiseEvent Message(“End Processing record of ID “  & dbRow (“ID”).ToString())




In the Console Application (C#) I defined a handler for the event



  using System;

  using System.IO;

  public delegate void UpdateAppMessageHandler(string myString);


 I defined the required function for the event handler



   internal class Program


        UpdateAppMessageHandler MySEvent = new UpdateAppMessageHandler (ConsolAppMessageHandler);


        static   void  ConsolAppMessageHandler(string sMessage)




Now I need to assign the Update Application event to the event handler in the Console Application


  private static void Main(string[] args)




                UpdateApp MyUpdateApp = null;

                MyUpdateApp = new UpdateApp ();

                MyUpdateApp.Message += ConsolAppMessageHandler; 




Now the Console Screen will show a message for Start/End processing of each record in the Database
Leave a comment

Posted by on September 17, 2008 in General, Photography


Tags: , , , , , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: