/// <summary> /// Initializes a new instance of the <see cref="WindowsTimerHandle"/> class. /// </summary> /// <param name="delay">The delay.</param> /// <param name="resolution">The resolution.</param> /// <param name="isPeriodic">if set to <c>true</c> [is periodic].</param> /// <param name="callback">The callback.</param> public WindowsTimerHandle(int delay, int resolution, bool isPeriodic, Action callback) { UserCallback = callback; EventType = isPeriodic ? TimerEventType.Periodic : TimerEventType.OneShot; InternalCallback = InternalCallbackImpl; TimerId = NativeMethods.BeginTimer((uint)delay, (uint)resolution, InternalCallback, UIntPtr.Zero, (uint)EventType); }
public TimingEvent(Int32 ticks, ActionControl ac, TimerEventType type) { this.TicksLeft = ticks; this.ActionControl = ac; this.EventType = type; this.completed = false; }
/// <summary> /// Initializes a new instance of the <see cref="TimerHint"/> class. /// </summary> /// <param name="remainingTime">The remaining time.</param> /// <param name="eventType">Type of the event.</param> /// <param name="name">The name.</param> /// <param name="properties">The properties.</param> public TimerHint(TimeSpan remainingTime, TimerEventType eventType, string name, PropertyCollection properties) { this.remainingTime = remainingTime; this.eventType = eventType; this.name = name; this.properties = properties; }
private static void ScheduleThread(int fireTime, MmTimerProc callback, TimerEventType schedulerType) { try { Stopwatch sw = new Stopwatch(); repeatSchedule: sw.Start(); while (sw.ElapsedMilliseconds < fireTime) { Thread.Sleep(1); } sw.Reset(); callback((uint)SchedulerCatalog.IndexOf(Thread.CurrentThread), 0, IntPtr.Zero, 0, 0); if (schedulerType == TimerEventType.TIME_PERIODIC) { goto repeatSchedule; } } catch (ThreadInterruptedException e) { Console.WriteLine($"Thread interrupted (callback={callback.Method.Name}())"); } }
public void ExecAction(TimerEventType actionType) { if (actionType == TimerEventType.Start) { button.BackColor = System.Drawing.Color.Green; TimingEvents.Add(new TimingEvent(endDelay, this, TimerEventType.End)); if (soundDestination != SoundDestination.None) { SoundData.soundDataDict[soundDestination.ToString()].PlaySound(); } SendSerial(BitConverter.GetBytes(startAction)); } else if (actionType == TimerEventType.End) { button.BackColor = System.Drawing.Color.Orange; SendSerial(BitConverter.GetBytes(startAction)); TimingEvents.Add(new TimingEvent(restartDelay, this, TimerEventType.Restart)); } else if (actionType == TimerEventType.Restart) { button.BackColor = System.Drawing.Color.Empty; button.Enabled = true; } }