Exemple #1
0
        static void DetectState()
        {
            string LocX = Cursor.Position.X.ToString();
            string LocY = Cursor.Position.Y.ToString();

            Thread.Sleep(1000);

            if (LocX == Cursor.Position.X.ToString() &&
                LocY == Cursor.Position.Y.ToString())
            {
                Step++;
            }
            else
            {
                if (Logged == true)
                {
                    PerformanceCounter Counter = new PerformanceCounter();
                    Counter.CategoryName = "Processor";
                    Counter.CounterName  = "% Processor Time";
                    Counter.InstanceName = "_Total";
                    Counter.NextValue();
                    Thread.Sleep(1000);

                    MachineState MS = new MachineState();
                    MS.IsActive        = true;
                    MS.Timing          = new ActivePassive();
                    MS.Timing.ToActive = DateTime.Now.ToString();
                    MS.CPU_Percentage  = Counter.NextValue().ToString() + "%";

                    Logger l = new Logger();
                    l.WriteLog(MS, FilePath);

                    Logged = false;

                    Step = 0;
                }
                else
                {
                    Step = 0;
                }
            }

            if (Step > WaitingSeconds && Logged == false)
            {
                PerformanceCounter Counter = new PerformanceCounter();
                Counter.CategoryName = "Processor";
                Counter.CounterName  = "% Processor Time";
                Counter.InstanceName = "_Total";
                Counter.NextValue();
                Thread.Sleep(1000);

                MachineState MS = new MachineState();
                MS.IsActive         = false;
                MS.Timing           = new ActivePassive();
                MS.Timing.ToPassive = DateTime.Now.ToString();
                MS.CPU_Percentage   = Counter.NextValue().ToString() + "%";

                Logger l = new Logger();
                l.WriteLog(MS, FilePath);

                Logged = true;

                Step = 0;
            }
        }