Example #1
0
        private static void MessageHandler(object args)
        {
            if (args is SleepEvent)
            {
                SleepChangeEventHandler h = OnSleepChange;

                if (h != null)
                {
                    h((SleepEvent)args);
                }
            }
            else if (args is PowerEvent)
            {
                PowerEvent pe = (PowerEvent)args;

                PowerLevelChangeEventHandler h = OnPowerLevelChange;

                s_CurrentPowerLevel = pe.Level;

                if (h != null)
                {
                    h(pe);
                }
            }
        }
Example #2
0
        /// <summary>
        /// The Sleep method puts the device into a sleeps state that is only woken by the events described in the paramter wakeUpEvents.
        /// Please note that if the event SystemTimer is not used, the system will not be woken up by any managed timers.  In addition,
        /// other threads will not be executed until this sleep call exits.  This method raises the OnSleepChange event.
        ///
        /// The MaximumTimeToActive property contains the timeout value for this call.
        /// </summary>
        /// <param name="level">Determines what level of sleep the system should enter.  The behavior of the level is determined
        /// by the hardware vendor.</param>
        /// <param name="wakeUpEvents">Determines the events that will cause the system to exit the given sleep level</param>
        public static void Sleep(SleepLevel level, HardwareEvent wakeUpEvents)
        {
            SleepChangeEventHandler h = OnSleepChange;

            if (h != null)
            {
                SleepEvent e = new SleepEvent();

                e.EventType    = SleepEventType.ChangeRequested;
                e.Level        = level;
                e.WakeUpEvents = wakeUpEvents;
                e.Time         = DateTime.UtcNow;

                h(e);
            }

            InternalSleep(level, wakeUpEvents);
        }