【发布时间】:2016-07-08 20:53:16
【问题描述】:
我在我的 UWP 应用程序中使用来自“kernel32.dll”的 SetWaitableTimer。由于我的应用程序,我希望计算机从睡眠中唤醒。如果我在调试模式下运行应用程序,它就可以工作。如果我在释放模式下运行它,则计算机不会唤醒。
如何让我的应用程序在实现模式下唤醒计算机?
private void Button_Click(object sender, RoutedEventArgs e)
{
Task.Factory.StartNew(SetWaitForWakeUpTime);
}
[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.dll", SetLastError = true)]
public static extern Int32 WaitForSingleObject(IntPtr handle, uint milliseconds);
static IntPtr handle;
static void SetWaitForWakeUpTime()
{
long duetime = -600000000;
handle = CreateWaitableTimer(IntPtr.Zero, true, "MyWaitabletimer");
SetWaitableTimer(handle, ref duetime, 0, IntPtr.Zero, IntPtr.Zero, true);
uint INFINITE = 0xFFFFFFFF;
int ret = WaitForSingleObject(handle, INFINITE);
}
【问题讨论】:
标签: c# dll uwp dllimport kernel32