Ricky Lupo

Ricky Lupo

  • NA
  • 1
  • 0

Stand by & Wake up

Aug 9 2008 3:45 AM
Hi everybody,
I'm trying to make an application that sets the pc on stand by mode and after 10 seconds wakes up the system.
My problem is that the system doesn't wake up! I tried also on a hold P3 450 mhz with XP pro and there I even couldn't get stand by mode.
I've designed a simple form with a button, when the button is pressed the system should go in s.by and then wake up, the code I used is the following:

Set stand by mode:

Application.SetSuspendState(PowerState.Suspend, true, false);

Wake up the system after 10 secs, with relative Dll import:

        [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;
public static void SetWaitForWakeUpTime()
{
      long duetime = -100000000; //-x0000000 = x sec
      handle = CreateWaitableTimer(IntPtr.Zero, true, "");
      SetWaitableTimer(handle, ref duetime, 0, IntPtr.Zero, IntPtr.Zero, true);
      handle = CreateWaitableTimer(IntPtr.Zero, true, "");
      SetWaitableTimer(handle, ref duetime, 0, IntPtr.Zero, IntPtr.Zero, true);
      uint INFINITE = 0xFFFFFFFF;
       int ret = WaitForSingleObject(handle, INFINITE);
}


Do you have any suggestion, thanks in advance

R.