public MainWindow() { InitializeComponent(); mainThreadId_ = Thread.CurrentThread.ManagedThreadId; ecgGenerator_ = new DataGen.Electrocardiogram(); #if USE_RENDERING_CALLBACK CompositionTarget.Rendering += CompositionTarget_Rendering; #elif USE_DISPATCHERTIMER timer_ = new DispatcherTimer(); timer_.Tick += Timer__Tick; timer_.Interval = new TimeSpan(0, 0, 0, 0, 100); timer_.Start(); #elif USE_MMTIMER timer_ = new MMTimer(Timer__Tick) { Interval = 50, }; timer_.Start(); #elif USE_TIMERQUEUETIMER cancellationTokenSource_ = new CancellationTokenSource(); timer_ = new TimerQueueTimer(); waitOrTimerDelegate_ = new WaitOrTimerDelegate(Timer__Tick); // Avoid GC timer_.Create(1000, 50, waitOrTimerDelegate_); #endif stopwatch_ = Stopwatch.StartNew(); }
public ScpTimer() { InitializeComponent(); Interval = 100; _callback = OnTick; }
public void Start(uint dueTime, uint period, WaitOrTimerDelegate callbackDelegate) { _callbackDelegate = callbackDelegate; IntPtr pParameter = IntPtr.Zero; timeBeginPeriod(1); bool success = CreateTimerQueueTimer( // Timer handle out phNewTimer, // Default timer queue. IntPtr.Zero is just a constant value that represents a null pointer. IntPtr.Zero, // Timer callback function _callbackDelegate, // Callback function parameter pParameter, // Time (milliseconds), before the timer is set to the signaled state for the first time. dueTime, // Period - Timer period (milliseconds). If zero, timer is signaled only once. period, (uint)Flag.WT_EXECUTEINIOTHREAD); if (!success) { throw new HighResolutionTimerException("Error creating QueueTimer, HighResolutionTimer"); } }
public void Create(uint dueTime, uint period, WaitOrTimerDelegate callbackDelegate) { IntPtr pParameter = IntPtr.Zero; int error = 0; bool success = CreateTimerQueueTimer( // Timer handle out phNewTimer, // Default timer queue. IntPtr.Zero is just a constant value that represents a null pointer. IntPtr.Zero, // Timer callback function callbackDelegate, // Callback function parameter pParameter, // Time (milliseconds), before the timer is set to the signaled state for the first time. dueTime, // Period - Timer period (milliseconds). If zero, timer is signaled only once. period, (uint)Flag.WT_EXECUTEDEFAULT); error = Marshal.GetLastWin32Error(); if (success == false) { throw new QueueTimerException("Error in Win32 CreateTimerQueueTimer function.", error); } }
public TimerQueueTimer(int intervalInMilliseconds) { Interval = intervalInMilliseconds; _callback = TimerCallback; //unsafe //{ // fixed(TimeCaps* pTimeCaps = &_timeCaps) // { // timeGetDevCaps((IntPtr)pTimeCaps, (uint)sizeof(TimeCaps)); // } //} IntPtr timeCapsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof (TimeCaps))); try { timeGetDevCaps(timeCapsPtr, (uint) Marshal.SizeOf(typeof (TimeCaps))); var timeCaps = (TimeCaps) Marshal.PtrToStructure(timeCapsPtr, typeof (TimeCaps)); //timeGetDevCaps((IntPtr)pTimeCaps, (uint)sizeof(TimeCaps)); Debug.WriteLine(String.Format("QueueTimer Resolution capability MIN: {0}\tMAX:{1}", timeCaps.wPeriodMin, timeCaps.wPeriodMax)); CreateTimerQueueTimer(out _timerPtr, IntPtr.Zero, _callback, IntPtr.Zero, 0, (uint) Interval, (uint) ExecuteFlags.WT_EXECUTEINTIMERTHREAD); } finally { Marshal.FreeHGlobal(timeCapsPtr); } }
private static extern bool CreateTimerQueueTimer( out IntPtr handle, IntPtr timerQueue, WaitOrTimerDelegate callback, IntPtr param, uint dueTime, uint period, uint flags);
private static extern bool CreateTimerQueueTimer( out IntPtr phNewTimer, [In, Optional] IntPtr TimerQueue, WaitOrTimerDelegate Callback, [In, Optional] IntPtr Parameter, uint DueTime, [Optional] uint Period, [Optional] uint Flags);
static extern bool CreateTimerQueueTimer( out IntPtr phNewTimer, // phNewTimer - Pointer to a handle; this is an out value IntPtr TimerQueue, // TimerQueue - Timer queue handle. For the default timer queue, NULL WaitOrTimerDelegate Callback, // Callback - Pointer to the callback function IntPtr Parameter, // Parameter - Value passed to the callback function uint DueTime, // DueTime - Time (milliseconds), before the timer is set to the signaled state for the first time uint Period, // Period - Timer period (milliseconds). If zero, timer is signaled only once uint Flags // Flags - One or more of the next values (table taken from MSDN): );
public TimerQueueTimer() { running = false; timerHandle = IntPtr.Zero; autoReset = true; synchronizingObject = null; callback = new WaitOrTimerDelegate(timerOrWaitFired); }
public GIFPlayer() { InitializeComponent(); this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true); // Set the timer callback UpdateFn = new WaitOrTimerDelegate(UpdateFrame); }
//----------------------------------------------- // Public member function //----------------------------------------------- public QueueTimer() { _HTimerQueue = CreateTimerQueue (); if (_HTimerQueue == IntPtr.Zero) { throw new Exception ("Cannot create Timer Queue"); } _WaitOrTimerDelegate = new WaitOrTimerDelegate (_QueueTimer_Elapsed); }
//----------------------------------------------- // Public member function //----------------------------------------------- public QueueTimer() { _HTimerQueue = CreateTimerQueue(); if (_HTimerQueue == IntPtr.Zero) { throw new Exception("Cannot create Timer Queue"); } _WaitOrTimerDelegate = new WaitOrTimerDelegate(_QueueTimer_Elapsed); }
public void Stop() { //bool success = DeleteTimerQueue(IntPtr.Zero); bool success = DeleteTimerQueueTimer( IntPtr.Zero, // TimerQueue - A handle to the (default) timer queue phNewTimer, // Timer - A handle to the timer IntPtr.Zero // CompletionEvent - A handle to an optional event to be signaled when the function is successful and all callback functions have completed. Can be NULL. ); int error = Marshal.GetLastWin32Error(); _callbackDelegate = null; //CloseHandle(phNewTimer); }
public void Create(uint dueTime, uint period, WaitOrTimerDelegate callback, WTFlags flags = WTFlags.WT_EXECUTEDEFAULT) { var ok = CreateTimerQueueTimer( out timerHandle_, IntPtr.Zero, callback, IntPtr.Zero, dueTime, period, (uint)flags); if (!ok) { throw new TimerQueueTimerException("Failed to create TimerQueueTimer."); } }
/// <summary> /// Initialize a new <see cref="TimerQueue"/> instance. /// </summary> public TimerQueue() { _timers = new FastLinkedList <Timer>(); _timerId = 0; _syncRoot = new object(); _delegate = new WaitOrTimerDelegate(this.Callback); GC.KeepAlive(_delegate); _hQueue = NativeMethods.CreateTimerQueue(); Debug.Assert(_hQueue != IntPtr.Zero); if (_hQueue == IntPtr.Zero) { int error = Marshal.GetLastWin32Error(); throw new Win32Exception(error, "Unable to create timer queue."); } }
static extern bool CreateTimerQueueTimer( out IntPtr phNewTimer, // phNewTimer - Pointer to a handle; this is an out value IntPtr TimerQueue, // TimerQueue - Timer queue handle. For the default timer queue, NULL WaitOrTimerDelegate Callback, // Callback - Pointer to the callback function IntPtr Parameter, // Parameter - Value passed to the callback function uint DueTime, // DueTime - Time (milliseconds), before the timer is set to the signaled state for the first time uint Period, // Period - Timer period (milliseconds). If zero, timer is signaled only once uint Flags // Flags - One or more of the next values (table taken from MSDN): // WT_EXECUTEINTIMERTHREAD The callback function is invoked by the timer thread itself. This flag should be used only for short tasks or it could affect other timer operations. // WT_EXECUTEINIOTHREAD The callback function is queued to an I/O worker thread. This flag should be used if the function should be executed in a thread that waits in an alertable state. // The callback function is queued as an APC. Be sure to address reentrancy issues if the function performs an alertable wait operation. // WT_EXECUTEINPERSISTENTTHREA The callback function is queued to a thread that never terminates. This flag should be used only for short tasks or it could affect other timer operations. // Note that currently no worker thread is persistent, although no worker thread will terminate if there are any pending I/O requests. // WT_EXECUTELONGFUNCTION Specifies that the callback function can perform a long wait. This flag helps the system to decide if it should create a new thread. // WT_EXECUTEONLYONCE The timer will be set to the signaled state only once. );
static extern bool CreateTimerQueueTimer( out IntPtr phNewTimer, // phNewTimer - Pointer to a handle; this is an out value IntPtr TimerQueue, // TimerQueue - Timer queue handle. For the default timer queue, NULL WaitOrTimerDelegate Callback, // Callback - Pointer to the callback function IntPtr Parameter, // Parameter - Value passed to the callback function uint DueTime, // DueTime - Time (milliseconds), before the timer is set to the signaled state for the first time uint Period, // Period - Timer period (milliseconds). If zero, timer is signaled only once uint Flags // Flags - One or more of the next values (table taken from MSDN): // WT_EXECUTEINTIMERTHREAD The callback function is invoked by the timer thread itself. This flag should be used only for short tasks or it could affect other timer operations. // WT_EXECUTEINIOTHREAD The callback function is queued to an I/O worker thread. This flag should be used if the function should be executed in a thread that waits in an alertable state. // The callback function is queued as an APC. Be sure to address reentrancy issues if the function performs an alertable wait operation. // WT_EXECUTEINPERSISTENTTHREAD The callback function is queued to a thread that never terminates. This flag should be used only for short tasks or it could affect other timer operations. // Note that currently no worker thread is persistent, although no worker thread will terminate if there are any pending I/O requests. // WT_EXECUTELONGFUNCTION Specifies that the callback function can perform a long wait. This flag helps the system to decide if it should create a new thread. // WT_EXECUTEONLYONCE The timer will be set to the signaled state only once. );
//[CLSCompliant(false)] public static void Create(uint dueTime, uint period, WaitOrTimerDelegate callbackDelegate) { if (callbackDelegate == null) { throw new ArgumentNullException("callbackDelegate"); } // Make sure to hold on to a reference of the callback delegate delegateRef = callbackDelegate; // enable high precision timeBeginPeriod(RESOLUTION); IntPtr pParameter = IntPtr.Zero; bool success = CreateTimerQueueTimer( // Timer handle out phNewTimer, // Default timer queue. IntPtr.Zero is just a constant value that represents a null pointer. IntPtr.Zero, // Timer callback function callbackDelegate, // Callback function parameter pParameter, // Time (milliseconds), before the timer is set to the signaled state for the first time. dueTime, // Period - Timer period (milliseconds). If zero, timer is signaled only once. period, // Execute the callback in the IO thread (uint)Flag.WT_EXECUTEINIOTHREAD); if (!success) { throw new QueueTimerException("Error creating QueueTimer"); } }
public void Create(uint dueTime, uint period, WaitOrTimerDelegate callbackDelegate) { IntPtr pParameter = IntPtr.Zero; bool success = CreateTimerQueueTimer( // Timer handle out phNewTimer, // Default timer queue. IntPtr.Zero is just a constant value that represents a null pointer. IntPtr.Zero, // Timer callback function callbackDelegate, // Callback function parameter pParameter, // Time (milliseconds), before the timer is set to the signaled state for the first time. dueTime, // Period - Timer period (milliseconds). If zero, timer is signaled only once. period, (uint)Flag.WT_EXECUTELONGFUNCTION | (uint)Flag.WT_EXECUTEINIOTHREAD); if (!success) throw new QueueTimerException("Error creating QueueTimer"); }
//[CLSCompliant(false)] public static void Create(uint dueTime, uint period, WaitOrTimerDelegate callbackDelegate) { if (callbackDelegate == null) throw new ArgumentNullException("callbackDelegate"); // Make sure to hold on to a reference of the callback delegate delegateRef = callbackDelegate; // enable high precision timeBeginPeriod(RESOLUTION); IntPtr pParameter = IntPtr.Zero; bool success = CreateTimerQueueTimer( // Timer handle out phNewTimer, // Default timer queue. IntPtr.Zero is just a constant value that represents a null pointer. IntPtr.Zero, // Timer callback function callbackDelegate, // Callback function parameter pParameter, // Time (milliseconds), before the timer is set to the signaled state for the first time. dueTime, // Period - Timer period (milliseconds). If zero, timer is signaled only once. period, // Execute the callback in the IO thread (uint)Flag.WT_EXECUTEINIOTHREAD); if (!success) throw new QueueTimerException("Error creating QueueTimer"); }
public void Delay(uint dueTime, WaitOrTimerDelegate callbackDelegate) { IntPtr pParameter = IntPtr.Zero; bool success = CreateTimerQueueTimer( // Timer handle out phNewTimer, // Default timer queue. IntPtr.Zero is just a constant value that represents a null pointer. IntPtr.Zero, // Timer callback function callbackDelegate, // Callback function parameter pParameter, // Time (milliseconds), before the timer is set to the signaled state for the first time. dueTime, // Period - Timer period (milliseconds). If zero, timer is signaled only once. 0, (uint)(Flag.WT_EXECUTEINIOTHREAD | Flag.WT_EXECUTEONLYONCE)); if (!success) { throw new QueueTimerException("Error creating QueueTimer"); } }
/// <summary> /// Initialize a new <see cref="TimerQueue"/> instance. /// </summary> public TimerQueue() { _timers = new FastLinkedList<Timer>(); _timerId = 0; _syncRoot = new object(); _delegate = new WaitOrTimerDelegate( this.Callback ); GC.KeepAlive( _delegate ); _hQueue = NativeMethods.CreateTimerQueue(); Debug.Assert( _hQueue != IntPtr.Zero ); if( _hQueue == IntPtr.Zero ) { int error = Marshal.GetLastWin32Error(); throw new Win32Exception( error, "Unable to create timer queue." ); } }
static extern bool CreateTimerQueueTimer( out IntPtr phNewTimer, IntPtr TimerQueue, WaitOrTimerDelegate Callback, IntPtr Parameter, uint DueTime, uint Interval, uint Flags);
/// <summary> /// Use this for periodic timer. DueTime is when it's /// fired first (can be 0 for immediate) and period is /// how often to fire subsequently /// </summary> /// <param name="dueTime">Time of first firing</param> /// <param name="period">Periodicity</param> /// <param name="callback">callback function</param> public TimerQueue(int dueTime, int period, WaitOrTimerDelegate callback) { _dueTime = (uint)dueTime; _period = (uint)period; _callback = callback; }
public static extern bool CreateTimerQueueTimer (ref IntPtr phNewTimer, IntPtr TimerQueue, WaitOrTimerDelegate Callback, IntPtr Parameter, uint DueTime, uint Period, TimerQueueFlags Flags);
private static extern bool CreateTimerQueueTimer(out IntPtr phNewTimer, IntPtr timerQueue, WaitOrTimerDelegate callback, IntPtr parameter, uint dueTime, uint period, ExecuteFlags flags);
public static extern bool CreateTimerQueueTimer( out IntPtr handle, IntPtr timerQueue, WaitOrTimerDelegate callback, IntPtr param, uint dueTime, uint period, uint flags);
static extern bool RegisterWaitForSingleObject(out IntPtr phNewWaitObject, IntPtr hObject, WaitOrTimerDelegate Callback, IntPtr Context, uint dwMilliseconds, uint dwFlags);
static extern bool CreateTimerQueueTimer(out IntPtr phNewTimer, IntPtr TimerQueue, WaitOrTimerDelegate Callback, IntPtr Parameter, uint DueTime, uint Period, uint Flags);