Windows操作系统能够从唤醒定时器唤醒多久?

我正在编写一个使用C ++和Win API的程序。 我使用SetSuspendState()API将系统发送到睡眠模式(可以唤醒唤醒计时器'DisableWakeEvent'设置为FALSE。)然后使用CreateWaitableTimer和SetWaitableTimer API设置实际计时器。 问题在于,如果在系统进入睡眠模式后过早设置唤醒计时器,系统有时不会唤醒。

所以我很好奇,自从系统进入睡眠模式之前,是否有一段时间必须通过,然后才能以编程方式唤醒定时器?


马上。 您的电脑可以使用计时器唤醒:

安排机器醒来

C#文章,如果你不介意:http://www.codeproject.com/Articles/49798/Wake-the-PC-from-standby-or-hibernation

using System;
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
using System.ComponentModel;
using System.Threading;

namespace WakeUPTimer
{
    class WakeUP
    {
        [DllImport("kernel32.dll")]
        public static extern SafeWaitHandle CreateWaitableTimer(IntPtr lpTimerAttributes, 
                                                                  bool bManualReset,
                                                                string lpTimerName);

        [DllImport("kernel32.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetWaitableTimer(SafeWaitHandle hTimer, 
                                                    [In] ref long pDueTime, 
                                                              int lPeriod,
                                                           IntPtr pfnCompletionRoutine, 
                                                           IntPtr lpArgToCompletionRoutine, 
                                                             bool fResume);

        public event EventHandler Woken;

        private BackgroundWorker bgWorker = new BackgroundWorker();

        public WakeUP()
        {
            bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork);
            bgWorker.RunWorkerCompleted += 
              new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted);
        }

        public void SetWakeUpTime(DateTime time)
        {
            bgWorker.RunWorkerAsync(time.ToFileTime());
        }

        void bgWorker_RunWorkerCompleted(object sender, 
                      RunWorkerCompletedEventArgs e)
        {
            if (Woken != null)
            {
                Woken(this, new EventArgs());
            }
        }

        private void bgWorker_DoWork(object sender, DoWorkEventArgs e) 
        {
            long waketime = (long)e.Argument;

            using (SafeWaitHandle handle = 
                      CreateWaitableTimer(IntPtr.Zero, true, 
                      this.GetType().Assembly.GetName().Name.ToString() + "Timer"))
            {
                if (SetWaitableTimer(handle, ref waketime, 0, 
                                       IntPtr.Zero, IntPtr.Zero, true))
                {
                    using (EventWaitHandle wh = new EventWaitHandle(false, 
                                                           EventResetMode.AutoReset))
                    {
                        wh.SafeWaitHandle = handle;
                        wh.WaitOne();
                    }
                }
                else
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
            }
        }

    }
}

或者从控制面板:http://www.anuko.com/content/world_clock/faq/enable_wake_timers.htm

链接地址: http://www.djcxy.com/p/62471.html

上一篇: How soon will Windows OS be able to wake from a wake timer?

下一篇: WaitForSingleObject times out too fast