private void DisposeInternal()
        {
            if (_disposed)
            {
                return;
            }

            SystemEvents.SessionEnding    -= SystemEvents_SessionEnding;
            SystemEvents.SessionSwitch    -= SystemEvents_SessionSwitch;
            SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;

            if (_timer != null)
            {
                _timer.Dispose();
                _timer = null;
            }

            if (_handleToPowerOnNotificationRegistration != IntPtr.Zero)
            {
                UnregisterPowerSettingNotification(_handleToPowerOnNotificationRegistration);
                _handleToPowerOnNotificationRegistration = IntPtr.Zero;
            }

            if (_handleToMonitorStateNotificationRegistration != IntPtr.Zero)
            {
                UnregisterPowerSettingNotification(_handleToMonitorStateNotificationRegistration);
                _handleToMonitorStateNotificationRegistration = IntPtr.Zero;
            }

            _disposed = true;
        }
示例#2
0
 /// <summary>
 /// Releases unmanaged and - optionally - managed resources.
 /// </summary>
 /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_timer != null)
         {
             _timer.Dispose();
             _timer = null;
         }
     }
 }
示例#3
0
        /// <summary>
        /// Create an instance bound to an action delegate and a minimum idle time.
        /// </summary>
        /// <param name="minimumIdleTime">The minium time of idle before actually performing the action.</param>
        public DelayedAction(IDelayTimer timer, TimeSpan minimumIdleTime)
        {
            if (timer == null)
            {
                throw new ArgumentNullException("timer");
            }

            _timer = timer;
            _timer.SetInterval(minimumIdleTime);
            _timer.Elapsed += HandleTimerElapsedEvent;
        }