예제 #1
0
        private void CollectTick()
        {
            CurrentWindow current;

            if (!BreakTime)
            {
                current = CurrentWindow.GetActiveWindow();
                if (current.ShouldDiscard())
                {
                    return;
                }

                CurrentWindow = current;
            }
            else
            {
                current = CurrentWindow.FromString("Break time");
            }

            TickInfo info = new TickInfo()
            {
                Window = current,
                Span   = DateTime.Now.Subtract(LastTick)
            };

            CurrentTimeSlice.Add(info);

            SessionTimeSpent[current.ProgramName]
                = GetSessionTimeSpent(current.ProgramName) + info.Span.Milliseconds;
        }
예제 #2
0
        public static CurrentWindow GetActiveWindow()
        {
            try
            {
                IntPtr handle = GetActiveWindowHandle();

                CurrentWindow window = new CurrentWindow();
                window.WindowTitle = GetWindowTitle(handle);
                window.ProgramPath = GetProgramPath(handle);
                window.ProgramName = GetProgramName(window.ProgramPath);

                return(window);
            }
            catch (Exception ex)
            {
                return(CurrentWindow.Empty);
            }
        }