public void WhenFirstProcessIsRunningAndThenStoppedShouldUpdateTheProcessStatus()
        {
            //Arrange
            Process demoProcess1 = Process.Start(_process1FilePath);

            //Act
            IProcessMonitor pMonitor = ProcessMonitorFactory.BuildDefaultOSProcessMonitor();

            pMonitor.RefreshInformation();

            //Assert
            Assert.AreEqual(2, pMonitor.NbOfProcesses, "NbOfProcesses assertion is wrong");
            Assert.AreEqual(1, pMonitor.NbOfNotRunningProcesses, "NbOfNotRunningProcesses assertion is wrong");
            Assert.AreEqual(1, pMonitor.NbOfRunningProcesses, "NbOfRunningProcesses assertion is wrong");
            Assert.AreEqual(ProcessState.Running, pMonitor.GetProcessInformation().First().State,
                            "ProcessState1 assertion is wrong");
            Assert.AreEqual(ProcessState.NotRunning, pMonitor.GetProcessInformation().Last().State,
                            "ProcessState2 assertion is wrong");

            //Act
            demoProcess1.Kill();
            pMonitor.RefreshInformation();

            //Assert
            Assert.AreEqual(2, pMonitor.NbOfProcesses, "NbOfProcesses assertion is wrong");
            Assert.AreEqual(2, pMonitor.NbOfNotRunningProcesses, "NbOfNotRunningProcesses assertion is wrong");
            Assert.AreEqual(0, pMonitor.NbOfRunningProcesses, "NbOfRunningProcesses assertion is wrong");
            Assert.AreEqual(ProcessState.NotRunning, pMonitor.GetProcessInformation().First().State,
                            "ProcessState1 assertion is wrong");
            Assert.AreEqual(ProcessState.NotRunning, pMonitor.GetProcessInformation().Last().State,
                            "ProcessState2 assertion is wrong");
        }
Exemple #2
0
        /// <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);
            }
        }
Exemple #3
0
        /// <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++;
            }
        }