Пример #1
0
 public static void Start()
 {
     if (StepDiagram != null)
     {
         throw new Exception("Unable to start twice. Already listening. Call HookEngine.Stop after calling HookEngine.Start");
     }
     activeWindowHandle  = Win.GetActiveWindow();
     StepDiagram         = new StepDiagram();
     cpuUsageCalculator  = new CpuUsageCalculator();
     currentProcessTimer = new Timer(CheckCpuUsage, null, 100, 100);
     HookEvents();
     StepDiagram.AddTaskActive(WindowsEvents.GetActiveWindowTitle(), Win.GetForegroundWindow());
 }
Пример #2
0
        public static StepDiagram Stop()
        {
            if (StepDiagram == null)
            {
                throw new Exception("Call to Stop() failed. Must call HookEngine.Start before calling HookEngine.Stop.");
            }

            lock (currentProcessTimerLocker)
            {
                currentProcessTimer.Change(Timeout.Infinite, Timeout.Infinite);
                currentProcessTimer.Dispose();
                currentProcessTimer = null;
            }

            cpuUsageCalculator = null;
            UnhookEvents();
            StepDiagram result = StepDiagram;

            result.PostProcess();
            StepDiagram = null;
            return(result);
        }