예제 #1
0
        /// <summary>
        /// Stops the debouncer and raises the <see cref="Debounced"/> event if <see cref="Running"/> is enabled.
        /// </summary>
        public void Flush()
        {
            if (Running)
            {
                timer.Stop();

                Debounced?.Invoke(this, value);
            }
        }
예제 #2
0
 private void DebouncerCallback(object state)
 {
     if (state is ObjectContainer oc)
     {
         oc.Timer.Dispose();
         _dict.TryRemove(oc.Key, out ObjectContainer tmp);
         var args = new DebouncerEventArgs()
         {
             Args = oc.Args
         };
         Debounced?.Invoke(this, args);
     }
 }
예제 #3
0
 public void EventRaised(object sender, T a)
 {
     lock (_timerLock)
     {
         _lastSender = sender;
         _lastObj    = a;
         if (_waitForStop && _timer != null)
         {
             try
             {
                 _timer.Change(Timeout.Infinite, Timeout.Infinite);
                 _timer.Dispose();
             }
             catch
             {
             }
             _timer = null;
         }
         if (_timer == null)
         {
             _timer = new Timer((o) =>
             {
                 lock (_timerLock)
                 {
                     try
                     {
                         Debounced?.Invoke(_lastSender, _lastObj);
                     }
                     finally
                     {
                         try
                         {
                             if (_timer != null)
                             {
                                 _timer.Dispose();
                             }
                         }
                         catch { }
                         _timer = null;
                     }
                 }
             }, null, _debounceMs, Timeout.Infinite);
         }
     }
 }
예제 #4
0
 /// <summary>
 /// Invokes the <see cref="Debounced"/> event.
 /// </summary>
 /// <param name="source">Reference to the object tha raised the event.</param>
 /// <param name="eventArgs">Timer event arguments.</param>
 private void OnElapsed(object source, ElapsedEventArgs eventArgs)
 {
     Debounced?.Invoke(this, value);
 }