static void Main(string[] args) { // start the service Console.WriteLine("Starting Communicator..."); Manager manager = new Manager(); if (manager.StartService()) { Console.WriteLine("Communicator is started successfully"); } else { Console.WriteLine("Communicator is started with errors"); } // stop the service if 'x' is pressed or a stop file exists Console.WriteLine("Press 'x' or create 'commstop' file to stop Communicator"); FileListener stopFileListener = new FileListener(Path.Combine(manager.AppDirs.CmdDir, "commstop")); while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.X || stopFileListener.FileFound)) { Thread.Sleep(ScadaUtils.ThreadDelay); } manager.StopService(); stopFileListener.Terminate(); stopFileListener.DeleteFile(); Console.WriteLine("Communicator is stopped"); }