Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than kernel32, prefix the name with the module name and a period.
SetWaitableTimer (kernel32)
.
C# Signature:
[DllImport("kernel32.dll")]
static extern bool SetWaitableTimer(IntPtr hTimer, [In] ref long pDueTime,
int lPeriod, TimerCompleteDelegate pfnCompletionRoutine,
IntPtr lpArgToCompletionRoutine, bool fResume);
// Class that sets a WIN32 WaitableTimer. The timer will wake up the PC if the PC
// is in standby or hibernation mode.
class WaitableTimer
{
public delegate void TimerSetDelegate();
public delegate void TimerCompleteDelegate();
//
public delegate void TimerSetDelegate();
public delegate void TimerCompleteDelegate();
public event TimerSetDelegate OnTimerSet;
public event TimerCompleteDelegate OnTimerCompleted;
public event TimerSetDelegate OnTimerSet;
public event TimerCompleteDelegate OnTimerCompleted;
// Setting up the timer, the long Interval value needs to be negative if
// you want to set up a delay in milliseconds. ie
// if Interval = -60000000 the timer will expire in 1 minute. Once expired it runs the
// TimerComplete delegate
//
Console.WriteLine("Setting WaitableTimer");
SetWaitableTimer(handle, ref Interval, 0, TimerComplete, IntPtr.Zero, true);
Console.WriteLine("Last Error = " + Marshal.GetLastWin32Error().ToString()); // The error may be 1004 (Invalid flags), this is not critical
Console.WriteLine("Timer set @ " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
// Setting up the timer, the long Interval value needs to be negative if
// you want to set up a delay in milliseconds. ie
// if Interval = -60000000 the timer will expire in 1 minute. Once expired it runs the
// TimerComplete delegate
//
Console.WriteLine("Setting WaitableTimer");
SetWaitableTimer(handle, ref Interval, 0, TimerComplete, IntPtr.Zero, true);
Console.WriteLine("Last Error = " + Marshal.GetLastWin32Error().ToString()); // The error may be 1004 (Invalid flags), this is not critical
Console.WriteLine("Timer set @ " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
// Starting a new thread which waits for the WaitableTimer to expire
//
Thread t_Wait = new Thread(new ThreadStart(WaitTimer));
t_Wait.Start();
// Starting a new thread which waits for the WaitableTimer to expire
//
Thread t_Wait = new Thread(new ThreadStart(WaitTimer));
t_Wait.Start();
// Raising Event Timer Set
//
if (OnTimerSet != null)
{
OnTimerSet();
}
}
private void WaitTimer()
// Raising Event Timer Set
//
if (OnTimerSet != null)
{
// Waiting for the timer to expire
//
if (WaitForSingleObject(handle, INFINITE) != 0)
{
Console.WriteLine("Last Error = " + Marshal.GetLastWin32Error().ToString());
}
else
{
Console.WriteLine("Timer expired @ " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
}
private void TimerCompleted()
{
// Routine executed once the timer has expired. This is executed independently of the
// program calling this class implementation of the OnTimerCompleted Event
//
Console.WriteLine("Timer is complete in the class");
}
private void TimerIsSet()
{
Console.WriteLine("Timer is set in the class");
}
}
Alternative Managed API:
Do you know one? Please contribute it!
private void WaitTimer()
{
// Waiting for the timer to expire
//
if (WaitForSingleObject(handle, INFINITE) != 0)
{
Console.WriteLine("Last Error = " + Marshal.GetLastWin32Error().ToString());
}
else
{
Console.WriteLine("Timer expired @ " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
}
private void TimerCompleted()
{
// Routine executed once the timer has expired. This is executed independently of the
// program calling this class implementation of the OnTimerCompleted Event
//
Console.WriteLine("Timer is complete in the class");
}
private void TimerIsSet()
{
Console.WriteLine("Timer is set in the class");
}
}
Alternative Managed API:
Do you know one? Please contribute it!
The SetWaitableTimer API
10/14/2011 3:46:02 AM - -84.22.151.40
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).