/// <summary> /// Остановка таймера /// </summary> public void Stop() { if (disposed) { throw new ObjectDisposedException("Timer"); } if (!running) { return; } int result = timeKillEvent(timerID); Debug.Assert(result == TIMERR_NOERROR); running = false; if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke( new EventRaiser(OnStopped), new object[] { EventArgs.Empty }); } else { OnStopped(EventArgs.Empty); } }
public void Start() { if (disposed) { throw new ObjectDisposedException("Timer"); } if (!IsRunning) { if (Mode == TimerMode.Periodic) { timerID = timeSetEvent(Period, Resolution, timeProcPeriodic, 0, (int)Mode); } else { timerID = timeSetEvent(Period, Resolution, timeProcOneShot, 0, (int)Mode); } if (timerID == 0) { throw new TimerStartException("Unable to start multimedia Timer."); } running = true; if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke(new EventRaiser(OnStarted), new object[1] { EventArgs.Empty }); } else { OnStarted(EventArgs.Empty); } } }
public void Start() { if (IsRunning) { return; } if (Mode == TimerMode.Periodic) { timerID = timeSetEvent((int)Interval.TotalMilliseconds, resolution, timeProcPeriodic, 0, (int)Mode); } else { timerID = timeSetEvent((int)Interval.TotalMilliseconds, resolution, timeProcOneShot, 0, (int)Mode); } if (timerID == 0) { throw new Exception("Unable to start multimedia Timer."); } IsRunning = true; if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke(new TickDelegate(OnStarted), new object[] { EventArgs.Empty }); return; } OnStarted(EventArgs.Empty); }
/// <summary> /// Stops timer. /// </summary> /// <exception cref="ObjectDisposedException"> /// If the timer has already been disposed. /// </exception> public void Stop() { if (_disposed) { return; } if (!IsRunning) { return; } // Stop and destroy timer. var result = NativeMethods.TimeKillEvent(_timerID); Debug.Assert(result == TIMERR_NOERROR); IsRunning = false; if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke( new EventRaiser(OnStopped), new object[] { EventArgs.Empty }); } else { OnStopped(EventArgs.Empty); } }
private void ElapsedThreadProc() { while (true) { m_waitHandle.WaitOne(); if (m_disposing) { return; } ElapsedEventArgs eea = new ElapsedEventArgs(DateTime.Now); if (Elapsed != null) { foreach (ElapsedEventHandler eeh in Elapsed.GetInvocationList()) { // determine if we're supposed to Invoke or not if (SynchronizingObject == null) { eeh(this, eea); } else { SynchronizingObject.Invoke(eeh, new object[] { this, eea }); } } } } }
private void DoNotifyBlockHeight(long aCurrencyId, long aCurrencyHeight) { try { SynchronizingObject?.BeginInvoke(OnBlockHeightChange, new object[] { this, aCurrencyId, aCurrencyHeight }); } catch (Exception e) { DoErrorHandler(e); } }
// this hides the parameter ugliness from the managed caller private void TimerCallbackShim(uint uTimerID, uint uMsg, ref uint dwUser, ref uint dw1, ref uint dw2) { if (this.SynchronizingObject != null) { SynchronizingObject.Invoke(new CallbackHandler(TimerCallback)); } else { TimerCallback(); } }
internal void DoTick() { if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke(tickRaiser, emptyArgs); } else { OnTick(EventArgs.Empty); } }
/// <summary> /// Starts the timer. /// </summary> /// <exception cref="ObjectDisposedException"> /// The timer has already been disposed. /// </exception> /// <exception cref="TimerStartException"> /// The timer failed to start. /// </exception> public void Start() { #region Require if (disposed) { throw new ObjectDisposedException("Timer"); } #endregion #region Guard if (IsRunning) { return; } #endregion // If the periodic event callback should be used. if (Mode == TimerMode.Periodic) { // Create and start timer. timerID = timeSetEvent(Period, Resolution, timeProcPeriodic, 0, (int)Mode); } // Else the one shot event callback should be used. else { // Create and start timer. timerID = timeSetEvent(Period, Resolution, timeProcOneShot, 0, (int)Mode); } // If the timer was created successfully. if (timerID != 0) { running = true; if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke( new EventRaiser(OnStarted), new object[] { EventArgs.Empty }); } else { OnStarted(EventArgs.Empty); } } else { throw new TimerStartException("Unable to start multimedia Timer."); } }
private void InvokeHandler(EventHandler <FileWatcherErrorEventArgs> eventHandler, FileWatcherErrorEventArgs e) { if (eventHandler != null) { if (SynchronizingObject != null && this.SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke(eventHandler, new object[] { this, e }); } else { eventHandler(this, e); } } }
/// <summary> /// Executes an event that occurs inside the running method pump. /// </summary> /// <remarks>Call the DoEvent to execute an event on the correct thread. /// This method checks if SinchronizingObject property is set and executes /// the event using the ISynchronizeInvoke interface. By doing so this /// insures that the event is fired only when the thread is in a valid state.</remarks> protected virtual void DoEvent(Delegate anEvent, bool asynchronous, params object[] args) { if (SynchronizingObject == null) { anEvent.DynamicInvoke(args); } else if (asynchronous) { SynchronizingObject.BeginInvoke(anEvent, args); } else { SynchronizingObject.Invoke(anEvent, args); } }
/// <summary> /// Called when a head movement is detected. /// </summary> /// protected virtual void OnFaceMove(FaceEventArgs args) { if (FaceMove != null) { if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke( FaceMove, new object[] { this, args }); } else { FaceMove(this, args); } } }
private void videoSource_PlayingFinished(object sender, ReasonToFinishPlaying reason) { if (PlayingFinished != null) { if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke( PlayingFinished, new object[] { this, reason }); } else { PlayingFinished(this, reason); } } }
private void videoSource_VideoSourceError(object sender, VideoSourceErrorEventArgs eventArgs) { if (VideoSourceError != null) { if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke( VideoSourceError, new object[] { this, eventArgs }); } else { VideoSourceError(this, eventArgs); } } }
void DynamicInvoke(Delegate method, params object[] args) { try { lock (OneChangeAtTheTime) method.DynamicInvoke(args); } catch (Exception ex) { // Add data to help with debugging. var prefix = string.Format("{0}<T>", nameof(ObservableCollectionInvoked <T>)) + "."; ex.Data.Add(prefix + "T", typeof(T).FullName); ex.Data.Add(prefix + "SynchronizingObject", SynchronizingObject?.GetType().FullName); ex.Data.Add(prefix + "AsynchronousInvoke", AsynchronousInvoke); throw; } }
/// <summary> /// Fires the <see cref="EventRecorded"/> event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="Microsoft.Win32.TaskScheduler.TaskEventArgs" /> instance containing the event data.</param> protected virtual void OnEventRecorded(object sender, TaskEventArgs e) { var h = EventRecorded; if (h == null) { return; } if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke(h, new object[] { this, e }); } else { h(sender, e); } }
protected override void OnObjectChanged(ObjectChangedEventArgs objChangedArgs) { EventHandler <ObjectChangedEventArgs> handlerCopy = m_objectChanged; if (handlerCopy != null) { if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke(handlerCopy, new object[] { this, objChangedArgs }); } else { handlerCopy(this, objChangedArgs); } Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "Fired the object changed event callback."); } }
protected virtual void OnApplicationChanged(ApplicationChangedEventArgs appChangedArgs) { EventHandler <ApplicationChangedEventArgs> handlerCopy = m_applicationChanged; if (handlerCopy != null) { if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke(handlerCopy, new object[] { this, appChangedArgs }); } else { handlerCopy(this, appChangedArgs); } Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "Fired the application changed event callback."); } }
protected void OnExited() { EventHandler eventHandler = onExited; if (eventHandler != null) { if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke(eventHandler, new object[] { this, EventArgs.Empty }); return; } eventHandler(this, EventArgs.Empty); } }
public void Stop() { if (!IsRunning) { return; } timeKillEvent(timerID); IsRunning = false; if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke(new TickDelegate(OnStopped), new object[] { EventArgs.Empty }); return; } OnStopped(EventArgs.Empty); }
/// <summary> /// Called when a face enters the scene. /// </summary> /// protected virtual void OnFaceEnter(FaceEventArgs args) { IsTracking = true; IsDetecting = false; if (FaceEnter != null) { if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke( FaceEnter, new object[] { this, args }); } else { FaceEnter(this, args); } } }
/// <summary> /// Called when the face being tracked leaves the scene. /// </summary> /// protected virtual void OnHeadLeave(EventArgs args) { IsTracking = false; IsDetecting = true; if (HeadLeave != null) { if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke( HeadLeave, new object[] { this, args }); } else { HeadLeave(this, args); } } }
internal void FixedErrorReadNotifyUser(string data) { DataReceivedEventHandler errorDataReceived = ErrorDataReceived; if (errorDataReceived != null) { DataReceivedEventArgs dataReceivedEventArgs = new DataReceivedEventArgs(data); if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.Invoke(errorDataReceived, new object[] { this, dataReceivedEventArgs }); return; } errorDataReceived(this, dataReceivedEventArgs); } }
/// <summary> /// Stops timer. /// </summary> /// <exception cref="ObjectDisposedException"> /// If the timer has already been disposed. /// </exception> public void Stop() { #region Require if (_disposed) { throw new ObjectDisposedException("Timer"); } #endregion #region Guard if (!_running) { return; } #endregion // Stop and destroy timer. int result = timeKillEvent(_timerId); Debug.Assert(result == TIMERR_NOERROR); _running = false; if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke( new EventRaiser(OnStopped), new object[] { EventArgs.Empty }); } else { OnStopped(EventArgs.Empty); } }
public void Stop() { if (disposed) { throw new ObjectDisposedException("Timer"); } if (running) { timeKillEvent(timerID); running = false; if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke(new EventRaiser(OnStopped), new object[1] { EventArgs.Empty }); } else { OnStopped(EventArgs.Empty); } } }
/// <summary> /// Starts the timer. /// </summary> /// <exception cref="ObjectDisposedException"> /// The timer has already been disposed. /// </exception> /// <exception cref="TimerStartException"> /// The timer failed to start. /// </exception> public void Start() { if (_disposed) { throw new ObjectDisposedException("Timer"); } if (IsRunning) { return; } // If the periodic event callback should be used. var userCtx = 0; _timerID = NativeMethods.TimeSetEvent(Period, Resolution, Mode == TimerMode.Periodic ? _timeProcPeriodic : _timeProcOneShot, ref userCtx, (int)Mode); // If the timer was created successfully. if (_timerID != 0) { IsRunning = true; if (SynchronizingObject != null && SynchronizingObject.InvokeRequired) { SynchronizingObject.BeginInvoke( new EventRaiser(OnStarted), new object[] { EventArgs.Empty }); } else { OnStarted(EventArgs.Empty); } } else { throw new TimerStartException("Unable to start multimedia Timer."); } }