static void Main(string[] args) { General.ApplicationHeader(true); LoadArgs(args); if (!DataFiles.LoadConfig()) { return; } try { Ssh ssh = new Ssh(); Thread tt = new Thread(new ThreadStart(ssh.ProptForCommands)); tt.Start(); while (WaitHandle.WaitAny(Defs.EventMonitor) != (int)EVENT_MON.SHUTDOWN) { ; } DateTime startDate = DateTime.UtcNow; //give it 3 seconds, if still running. while (tt.IsAlive && tt.ThreadState == ThreadState.Running && DateTime.UtcNow.Subtract(startDate).TotalSeconds < 3) { Thread.Sleep(1000); } //kill the thread if still alive. if (tt.IsAlive && tt.ThreadState == ThreadState.Running) { tt.Abort(); } } finally { Log.Verbose("Thread Closed..", ConsoleColor.DarkYellow); } }