/// <summary> /// Starts the timer. /// </summary> /// <param name="callback">A function to be called when the timer is signaled.</param> /// <param name="dueTime">The time at which the timer will be signaled.</param> /// <param name="period">The interval to use for periodic signaling, in milliseconds.</param> /// <param name="context">A value to pass to the callback function.</param> public void Set(TimerCallback callback, DateTime dueTime, int period, IntPtr context) { TimerApcRoutine apcRoutine = (context_, lowPart, highPart) => callback(context_); this.Handle.Set( dueTime.ToFileTime(), false, callback != null ? apcRoutine : null, context, period ); }
/// <summary> /// Starts the timer. /// </summary> /// <param name="callback">A function to be called when the timer is signaled.</param> /// <param name="dueTime">The due time, in milliseconds.</param> /// <param name="period">The interval to use for periodic signaling, in milliseconds.</param> /// <param name="context">A value to pass to the callback function.</param> public void Set(TimerCallback callback, int dueTime, int period, IntPtr context) { TimerApcRoutine apcRoutine = (context_, lowPart, highPart) => callback(context_); this.Handle.Set( dueTime * Win32.TimeMsTo100Ns, true, callback != null ? apcRoutine : null, context, period ); }
/// <summary> /// Sets the timer. /// </summary> /// <param name="dueTime">A due time, in 100ns units.</param> /// <param name="relative">Whether the due time is relative.</param> /// <param name="routine">A routine to call when the timer is signaled.</param> /// <param name="context">A value to pass to the timer callback routine.</param> /// <param name="resume"> /// Whether the power manager should restore the system when the timer is signaled. /// </param> /// <param name="period"> /// The time interval for periodic signaling of the timer, in milliseconds. /// Specify 0 for no periodic signaling. /// </param> /// <returns>The state of the timer (whether it is signaled).</returns> public bool Set(long dueTime, bool relative, TimerApcRoutine routine, IntPtr context, bool resume, int period) { long realDueTime = relative ? -dueTime : dueTime; bool previousState; // Keep the APC routine alive. Win32.NtSetTimer( this, ref realDueTime, routine, context, resume, period, out previousState ).ThrowIf(); return(previousState); }
/// <summary> /// Sets the timer. /// </summary> /// <param name="dueTime">A due time, in 100ns units.</param> /// <param name="relative">Whether the due time is relative.</param> /// <param name="routine">A routine to call when the timer is signaled.</param> /// <param name="context">A value to pass to the timer callback routine.</param> /// <param name="resume"> /// Whether the power manager should restore the system when the timer is signaled. /// </param> /// <param name="period"> /// The time interval for periodic signaling of the timer, in milliseconds. /// Specify 0 for no periodic signaling. /// </param> /// <returns>The state of the timer (whether it is signaled).</returns> public bool Set(long dueTime, bool relative, TimerApcRoutine routine, IntPtr context, bool resume, int period) { NtStatus status; long realDueTime = relative ? -dueTime : dueTime; bool previousState; // Keep the APC routine alive. _routine = routine; if ((status = Win32.NtSetTimer( this, ref realDueTime, routine, context, resume, period, out previousState )) >= NtStatus.Error) { Win32.Throw(status); } return(previousState); }
/// <summary> /// Sets the timer. /// </summary> /// <param name="dueTime">A due time, in 100ns units.</param> /// <param name="relative">Whether the due time is relative.</param> /// <param name="routine">A routine to call when the timer is signaled.</param> /// <param name="context">A value to pass to the timer callback routine.</param> /// <param name="period"> /// The time interval for periodic signaling of the timer, in milliseconds. /// Specify 0 for no periodic signaling. /// </param> /// <returns>The state of the timer (whether it is signaled).</returns> public bool Set(long dueTime, bool relative, TimerApcRoutine routine, IntPtr context, int period) { return(this.Set(dueTime, relative, routine, context, false, period)); }
/// <summary> /// Sets the timer. /// </summary> /// <param name="dueTime">A relative due time, in 100ns units.</param> /// <param name="routine">A routine to call when the timer is signaled.</param> /// <param name="period"> /// The time interval for periodic signaling of the timer, in milliseconds. /// Specify 0 for no periodic signaling. /// </param> /// <returns>The state of the timer (whether it is signaled).</returns> public bool Set(long dueTime, TimerApcRoutine routine, int period) { return(this.Set(dueTime, true, routine, IntPtr.Zero, period)); }