How soon will Windows OS be able to wake from a wake timer?
I'm writing a program using C++ and Win APIs. I employed SetSuspendState() API to send the system into a sleep mode (with a possibility to wake on a wake timer, 'DisableWakeEvent' set to FALSE.) I then use CreateWaitableTimer and SetWaitableTimer API to set the actual timer. The issue is that sometimes the system does not wake up if I set the wake timer too soon after the system enters the sleep mode.
So I was curious if there's a minimum time that has to pass since the system is sent into a sleep mode before it can be woken up with a wake timer programmatically?
Right now. Your PC can wake up using a timer:
Schedule machine to wake up
C# Article if you dont 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
链接地址: http://www.djcxy.com/p/62472.html