static void Main(string[] args) { //variable declartion int res = 1; using (var application = new RouterSocket("@tcp://127.0.0.1:9045")) //use router socket { Console.WriteLine("Press any key to exit the application."); Program objProgram = new Program(); //create obj in program class /* When the router scoket is not connected and the dealersocket not initiate the thread. In that case we must close the router using keypress event ... * regarding this sistuation we can't use the return or exit , So we are using the process.getcurrentprocess method to kille the process and exit * the application..*/ Thread threadCloseApplication = new Thread(() => { res = objProgram.fnThreadToCloseApplication(); if (res == 0) { var process = Process.GetCurrentProcess(); if (process.ProcessName == "Watchdog.vshost" || process.ProcessName == "Watchdog.exe" || process.ProcessName == "Watchdog") { process.Kill(); } } }); threadCloseApplication.Name = "CloseApplicationThread"; //declartion of thread name threadCloseApplication.Start(); //thread start while (true) //infinitive loop start { List <string> msg = application.ReceiveStringMessages(); //get msg from good and bad application Applicationname = msg[1].Split('_')[0]; //get application name from messages Console.WriteLine(msg[1]); //print the good and bad application messages if (goodflag == false && badflag == false) //check to start the timer at initial state only { if (Applicationname == "GoodApp") { goodflag = true; } else { badflag = true; } System.Timers.Timer myTimer = new System.Timers.Timer(1 * 15 * 1000); //initiate the timer myTimer.Start(); //timer start myTimer.Elapsed += new ElapsedEventHandler(goodTimer_Elapsed); //timer events elapsed } if (msg.Count == 3) //check msg count == 3 means get the bad application environment path { applicationpath = msg[2]; //assign tha bad application path in global } Applicationname = ""; } } }