/// <summary> /// On Windows, interrogate the status of the Notepad process every 3 seconds. You can open and close /// Notepad in order to see how the program responds to your changes. We print the output on the console. /// </summary> static void Main() { System.Console.WriteLine("PMonitor Example - Console"); IProcessMonitor pm = ProcessMonitorFactory.BuildDefaultOSProcessMonitor(); while (true) { pm.RefreshInformation(); BasicProcessInformation bpi = pm.GetProcessInformation().Single(); System.Console.WriteLine("{0} Process {1} is {2}", DateTime.Now.ToString(CultureInfo.InvariantCulture), bpi.FriendlyName, bpi.State.ToString()); Thread.Sleep(3000); } }
static void Main() { System.Console.WriteLine("PMonitor Example - Console with custom process monitor impl"); //We can not use the factory to create our process monitor, bacause the factory only //returns the built in implementaitons. However, we can just new-up our //concrete instance. IProcessMonitor pm = new NoFileConfigProcessMonitor(); while (true) { pm.RefreshInformation(); BasicProcessInformation bpi = pm.GetProcessInformation().Single(); System.Console.WriteLine("{0} Process {1} is {2}", DateTime.Now.ToString(CultureInfo.InvariantCulture), bpi.FriendlyName, bpi.State.ToString()); Thread.Sleep(3000); } }
/// <summary> /// On Windows, interrogate the status of the Notepad process every 3 seconds. You can open and close /// Notepad in order to see how the program responds to your changes. We print the output on the console. /// </summary> static void Main() { System.Console.WriteLine("PMonitor BoehmTrader - Console"); IProcessMonitor pm = ProcessMonitorFactory.BuildDefaultOSProcessMonitor(); while (true) { pm.RefreshInformation(); BasicProcessInformation bpi = pm.GetProcessInformation().Single(); if (numMonitoring % 10 == 0) { System.Console.WriteLine("{0} Process {1} is {2}", DateTime.Now.ToString(CultureInfo.InvariantCulture), bpi.FriendlyName, bpi.State.ToString()); } if (bpi.State == ProcessState.NotRunning) { StartProcess(); } Thread.Sleep(500); numMonitoring++; } }
public static extern SYSTEM_ERROR_CODE NtQueryInformationProcess(IntPtr ProcessHandle, int ProcessInformationClass, ref BasicProcessInformation ProcessInformation, uint ProcessInformationLength, out int ReturnLength);