private static void Main(string[] args) { Console.WriteLine("This is an application monitoring tool. It monitors necessary process and stops it if it is launched " + "more than provided amount of time (in minutes)"); Console.WriteLine("Usage: monitor.exe <processName> <processTimeout> <processCheckInterval>"); Console.WriteLine("Example: monitor.exe notepad 5 1"); if (args.Length < 3) { Console.WriteLine("Incorrect number of parameters!"); Console.WriteLine("Usage: Monitor.exe <processName> <processTimeout> <processCheckInterval>"); return; } if (!int.TryParse(args[1], out var timeout) || timeout <= 0) { Console.WriteLine("Please provide a timeout argument as positive integer"); return; } if (!int.TryParse(args[2], out var checkInterval) || checkInterval <= 0) { Console.WriteLine("Please provide a check interval argument as a positive integer"); return; } var proc = new ProcessMonitor(args[0]); if (proc.IsProcessRunning() != true) { Console.WriteLine($"Process '{proc.Name}' is not running. Exiting..."); return; } proc.Monitor(timeout, checkInterval); ProcessMonitor.FreezeOnScreen(); }
static void Main(string[] args) { while (true) { System.Threading.Thread.Sleep(5 * 1000); var res = ProcessMonitor.IsProcessRunning("PKPSAssets.Agent.WebApi"); Console.WriteLine("Process Running {0}", res); //while(true) //{ // System.Threading.Thread.Sleep(5 * 1000); // var res = ProcessMonitor.IsProcessRunning("PKPSAssets.Agent.WebApi"); // Console.WriteLine("Process Running {0}", res); // if(!res) // { // try // { // (new System.Threading.Thread(() => CommandLine.RunExternalExe(@"D:\Source\DotNet\PKPSAssets\PKPSAssetsServices\PKPSAssets.Agent.WebApi\bin\Debug\PKPSAssets.Agent.WebApi.exe"))).Start(); // } // catch (Exception ex) // { // } // //Process process = Process.Start(@"D:\Source\DotNet\PKPSAssets\PKPSAssetsServices\PKPSAssets.Agent.WebApi\bin\Debug\PKPSAssets.Agent.WebApi.exe"); // //int id = process.Id; // //Process tempProc = Process.GetProcessById(id); // ////this.Visible = false; // //tempProc.WaitForExit(); // //this.Visible = true; // } //} Encrypt(); Console.ReadKey(); } }