Beispiel #1
0
        public async Task RequestStart()
        {
            LASTINPUTINFO lastInPut = new LASTINPUTINFO();

            lastInPut.cbSize = (uint)Marshal.SizeOf(lastInPut);
            State            = IdleDetectorState.Running;

            while (!cancelRequested)
            {
                try
                {
                    GetLastInputInfo(ref lastInPut);
                }
                catch
                {
                    EnableRaisingEvents = false;
                    break;
                }
                IdleDuration = (Environment.TickCount - lastInPut.dwTime) / 1000;

                if (EnableRaisingEvents && (IsSystemIdle() != previousSystemInputIdle))
                {
                    previousSystemInputIdle = IsSystemIdle();
                    IdleStateChanged?.Invoke(null, null);
                }
                await Task.Delay(UpdateInterval);
            }

            cancelRequested = false;
            State           = IdleDetectorState.Stopped;
        }
Beispiel #2
0
 protected void RaiseIdleStateChanged(IdleStateEventArgs eventArgs)
 {
     IdleStateChanged?.Invoke(this, eventArgs);
 }