/// <summary>
        /// Run Process Monitor
        /// </summary>
        /// <param name="args"></param>
        public void Run(string[] args)
        {
            try
            {
                if (args.Length > 0 && args[0].Equals("-debug"))
                {
                    // show console window when arg="debug" is passed
                    var winHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
                    ShowWindow(winHandle, SW_RESTORE);
                }
                else if (args.Length == 0)
                {
                    // hide the console window when arg is not passed
                    var winHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
                    ShowWindow(winHandle, SW_HIDE);
                }

                // Set the console background.
                Console.BackgroundColor = ConsoleColor.White;
                // Set the foreground color.
                Console.ForegroundColor = ConsoleColor.Black;
                // Clear the console.
                Console.Clear();

                Console.WriteLine("Starting Process Monitor");

                processMonitorService = new ProcessMonitorService();
                processMonitorService.Execute();
            }
            catch (Exception ex)
            {
                Console.WriteLine("An Error Occurred: {0}", ex);
            }
        }
Exemplo n.º 2
0
 public PMService()
 {
     this.ServiceName = ServiceNameConst;
     this.CanStop     = true;
     // Create an instance of ProcessMonitorService
     this.processMonitorService = new ProcessMonitorService();
 }
 /// <summary>
 /// Method used to dispose of the resources when application exits
 /// </summary>
 public void Dispose()
 {
     if (processMonitorService != null)
     {
         processMonitorService.Dispose();
         processMonitorService = null;
     }
 }