Exemple #1
0
        /// <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);
            }
        }
Exemple #2
0
        /// <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);
            }
        }
Exemple #3
0
 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);
 }
Exemple #4
0
 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);
         }
     }
 }
Exemple #5
0
 private void DoNotifyBlockHeight(long aCurrencyId, long aCurrencyHeight)
 {
     try
     {
         SynchronizingObject?.BeginInvoke(OnBlockHeightChange, new object[] { this, aCurrencyId, aCurrencyHeight });
     }
     catch (Exception e)
     {
         DoErrorHandler(e);
     }
 }
Exemple #6
0
 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);
         }
     }
 }
Exemple #9
0
 /// <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);
     }
 }
Exemple #10
0
 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);
         }
     }
 }
Exemple #11
0
 /// <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);
         }
     }
 }
Exemple #12
0
 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);
         }
     }
 }
        /// <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.");
            }
        }
Exemple #15
0
        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.");
            }
        }
Exemple #16
0
 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);
 }
        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);
            }
        }
Exemple #18
0
        /// <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);
                }
            }
        }
Exemple #19
0
        /// <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);
                }
            }
        }
Exemple #20
0
        /// <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);
            }
        }
Exemple #21
0
 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);
         }
     }
 }
Exemple #22
0
        /// <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.");
            }
        }