Hi Below is the code i am using to waking up my device:
Device : INTEL NUC device
Windows : Windows 10 Enterprise
version: 21H2
OS Build: 19044.2604
A. For short duration(when wake is schedule after 2-3 mins) it is accurate.
B. But if it is schedule for wake after long time (1-1.5 days after) : It takes around 10-15min after delay to wake up.
C. But if it is schedule for wake after more longer time(> 2 days after): It takes around 40-50 mins after delay to wake up.
Can you tell why is it so ? Is it due to quartz clock or system clock not sync?
Pls help to debug it
On both devices S3 sleep state is present (Hibernate ,S0(modern standby ,hybrid sleep are disabled).
using Signage.DataModel;
using Signage.Service;
using Signage.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Signage.Utilities
{
public class TaskScheduler
{
public delegate void TimerCompleteDelegate();
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(TaskScheduler));
public static void completionRoutine()
{
Log.Info(".................................... complete .................");
}
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr CreateWaitableTimer(IntPtr lpTimerAttributes, bool bManualReset, string lpTimerName);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool SetWaitableTimer(IntPtr hTimer, [In] ref long pDueTime, int lPeriod, TimerCompleteDelegate pfnCompletionRoutine, IntPtr pArgToCompletionRoutine, bool fResume);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool CancelWaitableTimer(IntPtr hTimer);
[DllImport("powrprof.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetSuspendState(bool hibernate, bool forceCritical, bool disableWakeEvent);
private static IntPtr handle;
static bool isNull = true;
public static bool Hibernate()
{
return SetSuspendState(true, false, false);
}
public static void DisposeAndUpdateAppView()
{
StoredCredentialModel.GetInstance().IsAppInSleep = true;
AppState.GetInstance().DisposeDisplayUI();
}
public static bool Sleep()
{
// DisposeAndUpdateAppView();
Log.Info("device is on sleep mode ");
return SetSuspendState(false, false, false);
}
public static IntPtr SetWakeAt(DateTime dt)
{
TimerCompleteDelegate timerComplete = new TimerCompleteDelegate(completionRoutine);
// read the manual for SetWaitableTimer to understand how this number is interpreted.
long interval = dt.ToFileTimeUtc();
if (isNull)
{
handle = CreateWaitableTimer(IntPtr.Zero, true, "WaitableTimer");
isNull = false;
}
SetWaitableTimer(handle, ref interval, 0, null, IntPtr.Zero, true);
return handle;
}
}
}