/// <summary> /// Runs the task manager from the console. /// </summary> private static void RunFromConsole() { Console.WriteLine("Press ENTER to locate task modules."); Console.ReadLine(); TaskManagerService.LogInfo("Initializing service..."); try { TaskSupervisor.Initialize(); ModuleSupervisor.Initialize(); } catch (Exception e) { TaskManagerService.LogError("Unable to initialize service.", e); return; } Console.WriteLine("Press ENTER to start."); Console.ReadLine(); try { TaskManagerService.LogInfo("Service successfully started..."); ModuleSupervisor.Execute(); } catch (Exception e) { TaskManagerService.LogError("Unable to start service.", e); return; } Console.WriteLine("Press ENTER to stop."); // If you are debugging, you can freeze the main thread here. Console.ReadLine(); TaskManagerService.LogInfo("Stopping service..."); try { ModuleSupervisor.Shutdown(); TaskSupervisor.Shutdown(); TaskManagerService.LogInfo("Service successfully stopped..."); } catch (Exception e) { TaskManagerService.LogError("Unable to stop service.", e); return; } Console.WriteLine("Press ENTER to finish."); Console.ReadLine(); }
/// <summary> /// Called when the service is being stopped by the SCM. /// </summary> protected override void OnStop() { LogInfo("Stopping service..."); try { ModuleSupervisor.Shutdown(); TaskSupervisor.Shutdown(); LogInfo("Service successfully stopped..."); } catch (Exception e) { LogError("Unable to stop service.", e); throw; } lock (_eventLog) { _eventLog.Close(); _eventLog = null; } }
private static void RunFromConsole(string[] args) { ShowHeader(); TaskManagerOptions options; try { options = TaskManagerOptions.Create("TaskManager.exe", args); } catch (Exception ex) { Show("Argument parsing error: "); Show(ex.Message); Show("Try `TaskManager --help` for more information"); Environment.Exit(3); return; } if (options.ShowHelp) { Show(options.HelpText); return; } WaitUserInteraction(options, "Press ENTER to locate task modules."); TaskManagerService.LogInfo("Initializing service..."); try { Show("Event log: {0}", options.EventLog.GetType().Name); Show("Stats strategy: {0}", options.StatsStrategy.GetType().Name); TaskSupervisor.Initialize(options.StatsStrategy); TaskManagerService.Initialize(options.EventLog); ModuleSupervisor.Initialize(); } catch (Exception e) { TaskManagerService.LogError("Unable to initialize service.", e); WaitUserInteraction(options); return; } WaitUserInteraction(options, "Press ENTER to start."); try { TaskManagerService.LogInfo("Service successfully started..."); ModuleSupervisor.Execute(); if (options.NonStop && options.NonStopWait > 0) { Show("Waiting {0} milliseconds to tasks execution...", options.NonStopWait); Thread.Sleep(options.NonStopWait); } } catch (Exception e) { TaskManagerService.LogError("Unable to start service.", e); WaitUserInteraction(options); return; } // If you are debugging, you can freeze the main thread here. WaitUserInteraction(options, "Press ENTER to stop."); TaskManagerService.LogInfo("Stopping service..."); try { ModuleSupervisor.Shutdown(); TaskSupervisor.Shutdown(); TaskManagerService.LogInfo("Service successfully stopped..."); } catch (Exception e) { TaskManagerService.LogError("Unable to stop service.", e); return; } WaitUserInteraction(options, "Press ENTER to finish."); }