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;
         }
     }
 }