SetWaitableTimer fail #1013
Answered
by
AArnott
Gavin-Williams
asked this question in
Q&A
-
|
I have the following code... // create a waitable timer object
SafeHandle hTimer = CreateWaitableTimerEx(
lpTimerAttributes: null,
lpTimerName: "FrameTimer",
dwFlags: CREATE_WAITABLE_TIMER_HIGH_RESOLUTION,
dwDesiredAccess: (uint)FILE_ACCESS_RIGHTS.SYNCHRONIZE);
if (hTimer == null)
{
Console.WriteLine("CreateWaitableTimerEx failed : " + Marshal.GetLastWin32Error());
return;
}
// wait 5 seconds
long lpDueTime = -100000000L;
int lPeriod = 0;
if (!SetWaitableTimer(hTimer, in lpDueTime, lPeriod, null, null, false))
{
Console.WriteLine("SetWaitableTimer failed : " + Marshal.GetLastWin32Error());
return;
}But I'm getting an error 6 (invalid handle) on the SetWaitableTimer call. I notice that CreateWaitableTimerEx returns a SafeFileHandle. Is that an issue? Or what have I done wrong here? |
Beta Was this translation helpful? Give feedback.
Answered by
AArnott
Aug 10, 2023
Replies: 1 comment
-
|
Your null check is incorrect. When you apply this change: -if (hTimer == null)
+if (hTimer.IsInvalid)You'll find you get error 87. If you throw I'm no expert on this API, but my guess is it's your |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Gavin-Williams
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your null check is incorrect. When you apply this change:
You'll find you get error 87. If you throw
Win32Exceptionyou get the full error message, which indicates you have an invalid parameter in the first of your two calls.I'm no expert on this API, but my guess is it's your
dwDesiredAccessargument.