두 개의 Windows 10 PC 모두 Fall Creators Update를 실행하고 최신 패치가 모두 설치되어 있습니다. 하나는 타이머가 CreateWaitableTimer/SetWaitableTimer를 통해 설정된 후에 잠에서 깨어나고, 다른 하나는 문제가되지 않습니다. 깨어나지 않는 것은 내 DVR이고 요청시 깨울 수 있어야하기 때문입니다 :).SetWaitableTimer() 호출 후 내 Windows 10 PC가 왜 깨어나지 않습니까?
최대 절전 모드가 활성화되어 있지 않습니다.
시스템에서 깨어나기를 거부하는 비정상적인 이벤트를 볼 수 없습니다. 수동 웨이크 업을하거나 wake-on-lan 패킷을 보내지 않는 한 웨이크 업하지 않습니다. 확인하거나 어떤 추가 진단 단계를 많이 주시면 감사하겠습니다 취할 무엇에
public class Program
{
[ DllImport("kernel32.dll") ]
private static extern SafeWaitHandle CreateWaitableTimer(IntPtr lpTimerAttributes, bool bManualReset,
string lpTimerName);
[ DllImport("kernel32.dll", SetLastError = true) ]
[ return : MarshalAs(UnmanagedType.Bool) ]
private static extern bool SetWaitableTimer(SafeWaitHandle hTimer, [ In ] ref long pDueTime, int lPeriod,
IntPtr pfnCompletionRoutine, IntPtr lpArgToCompletionRoutine, bool fResume);
[DllImport("kernel32.dll", SetLastError = true)]
private 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 ILogger _logger;
private static bool Hibernate()
{
bool retVal = SetSuspendState(true, false, false);
_logger.Information(retVal
? $"Returning from hibernation at {DateTime.Now.ToLongTimeString()}"
: $"Failed to enter hibernation, error message was {Marshal.GetLastWin32Error()}");
return retVal;
}
private static bool Sleep()
{
bool retVal = SetSuspendState(false, false, false);
_logger.Information(retVal
? $"Returning from sleep at {DateTime.Now.ToLongTimeString()}"
: $"Failed to enter sleep, error message was {Marshal.GetLastWin32Error()}");
return retVal;
}
private static void SetWakeTimer(int minutes, bool hibernate)
{
DateTime utc = DateTime.Now.AddMinutes(minutes);
long duetime = utc.ToFileTime();
using(SafeWaitHandle handle = CreateWaitableTimer(IntPtr.Zero, true, "SleepWakeTimerTest"))
{
if(SetWaitableTimer(handle, ref duetime, 0, IntPtr.Zero, IntPtr.Zero, true))
{
_logger.Information($"Timer set, will trigger at {utc.ToLongTimeString()}");
if (hibernate) Hibernate();
else Sleep();
}
else
Console.WriteLine($"CreateWaitableTimer failed, error message was {Marshal.GetLastWin32Error()}");
}
}
static void Main(string[] args)
{
_logger = new LoggerConfiguration()
.WriteTo.File($"log-{DateTime.Now:yyyy-M-d-hhmmss}.txt")
.CreateLogger();
_logger.Information("parsing command line arguments...");
var cmdLine = new FluentCommandLineParser();
int delay = 2;
bool hibernate = false;
cmdLine.Setup<int>('d', "delay")
.Callback(x => delay = x)
.SetDefault(2)
.WithDescription("wakeup delay, in minutes");
cmdLine.Setup<bool>('h', "hibernate")
.Callback(x => hibernate = x)
.SetDefault(false)
.WithDescription("hibernate if flag set, otherwise sleep");
SetWakeTimer(delay, hibernate);
}
}
제안 :
는 여기에 내가 두 시스템에서 실행있어 C# 테스트 코드입니다. 정보
추가
그것은 내가 (즉, 작업 스케줄러 응용 프로그램을 사용하여) 수동으로 정의 예약 된 작업을 통해 컴퓨터를 깨어 시도 할 것을 제안했다. 흥미롭게도이 작업으로 컴퓨터가 깨어나지 않았습니다.
'이 작업을 실행하는 컴퓨터 깨우기'작업 일정이 작동합니까? https://www.howtogeek.com/119028/how-to-make-your-pc-wake-from-sleep-automatically/ –
** 우수 ** 제안, 스티브, 고맙습니다! 내가 배운 것에 기초하여 내 질문을 수정했습니다. –