I'm trying to make my pc wake up in case it has gotten into sleep mode. I found this code snippet on some website, but the Messagebox I added at the end always returns immediately.
I have also enabled my system for the use of wake timers in the power options.
[DllImport("kernel32.dll")]
public static extern IntPtr CreateWaitableTimer(IntPtr lpTimerAttributes,
bool bManualReset, string lpTimerName);
[DllImport("kernel32.dll")]
public static extern bool SetWaitableTimer(IntPtr hTimer, [In] ref long
pDueTime, int lPeriod, IntPtr pfnCompletionRoutine, IntPtr
lpArgToCompletionRoutine, bool fResume);
[DllImport("kernel32", SetLastError = true, ExactSpelling = true)]
public static extern Int32 WaitForSingleObject(IntPtr handle, uint
milliseconds);
static IntPtr handle;
private void SetWaitForWakeUpTime()
{
long duetime = 1200000000;
handle = CreateWaitableTimer(IntPtr.Zero, true, "MyWaitabletimer");
SetWaitableTimer(handle, ref duetime, 0, IntPtr.Zero, IntPtr.Zero, true);
uint INFINITE = 0xFFFFFFFF;
int ret = WaitForSingleObject(handle, INFINITE);
MessageBox.Show("wake up !");
}
and I'm calling it like this:
private void buttonTest_Click(object sender, EventArgs e)
{
SetWaitForWakeUpTime();
}
Theoretically this should only be signalled after 2 minutes, right? Why is it signalled right away and how do I correct it?