How soon can Windows wake up with a watchdog timer?

I am writing a program using C ++ and Win API. I used the SetSuspendState () API to put the system to sleep (with the ability to wake up with a wake timer, DisableWakeEvent set to FALSE.) Then I use the CreateWaitableTimer and SetWaitableTimer API to set the actual timer. The problem is that sometimes the system does not wake up if I set the tracking timer too quickly after the system goes into sleep mode.

So, I was curious if there is a minimum amount of time that must pass since the system goes into sleep mode before it can be woken up by a program timer.

+4
source share
1 answer

Right now. Your computer may wake up with a timer:

Awakening Machine Schedule

C # Article if you don't mind: 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()); } } } } } 

Or from the control panel: http://www.anuko.com/content/world_clock/faq/enable_wake_timers.htm

+1
source

Source: https://habr.com/ru/post/1432393/


All Articles