I want to implement a simple console that continuously listens for an
event from a custom object. I am unable to capture the events from
the object.
If I subscribe to the events in a windows app it works fine. Any
idea?
using System;
using MyTestApp.Messa ging;
using MyTestApp.Busin essLayer;
using System.Threadin g;
namespace MyTestApp.Liste ner
{
/// <summary>
/// MyTestApp.Liste ner.Run
/// </summary>
class Run
{
/// <summary>
/// Constructor
/// </summary>
public Run()
{
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
Background background = new Background();
Thread th = new Thread(new ThreadStart(bac kground.SpinInf inite));
th.Priority = ThreadPriority. Lowest;
th.Start();
Run run = new Run();
ObjectSubscribe r _ObjSubs = new ObjectSubscribe r("_LOCAL.Test" );
_ObjSubs.Object Received += new ObjectReceivedE vent(run.DoProc ess);
Console.WriteLi ne("Listening") ;
}
catch(Exception ex)
{
Console.WriteLi ne(ex.Message);
Console.ReadLin e();
}
}
/// <summary>
/// This is the event handler
/// </summary>
/// <param name="objTest"> event args</param>
public void DoProcess(objec t objTest)
{
TestObject obj = (TestObject)obj Test;
Console.WriteLi ne("Object Received : ");
Console.WriteLi ne("N1="+ obj.n1);
Console.WriteLi ne("N2="+ obj.n2);
Console.WriteLi ne("STR="+ obj.str);
}
}
}
//----- BACKGROUND.CS---------------------
namespace MyTestApp.TestL istener
{
/// <summary>
/// Background class keeps the process alive.
/// </summary>
public class Background
{
public Background()
{
}
public bool Terminate = false;
public void SpinInfinite()
{
while (!Terminate)
{
Thread.Sleep(ne w TimeSpan(0,0,3) );
}
}
}
}