private void Loop() { var token = _cancellationToken.Token; while (!token.IsCancellationRequested) { try { using (_mainRoutine = new MainRoutine()) { _mainRoutine.Start(); } } catch (Exception ex) { Console.WriteLine(ex); } finally { if (!token.IsCancellationRequested) { _cancellationToken.Token.WaitHandle.WaitOne(TimeSpan.FromSeconds(15)); } } } }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { PrtgTelegramBot service = new PrtgTelegramBot(); if (Environment.UserInteractive) { MainRoutine runMainRoutine = new MainRoutine(); runMainRoutine.Start(); } else { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new PrtgTelegramBot() }; ServiceBase.Run(ServicesToRun); } }