Esempio n. 1
0
        ///
        /// <summary>
        /// After <paramref name="tickTimeInSeconds" /> seconds, <paramref name="onTick" /> will be invoked.
        /// The resulting <see cref="TickEvent" /> is composed with the <paramref name="service" /> to generate an Event.
        /// </summary>
        /// <param name="tickTimeInSeconds">
        /// Number of seconds to wait before calling the event back.
        /// <note>Because only a single thread calls the events back, it may be called back sooner.</note>
        /// </param>
        /// <param name="service">Name of the service to send to Riemann</param>
        /// <param name="onTick">Function to call back after wait period</param>
        /// <returns>
        /// A disposable that, if called, will remove this callback from getting called.
        /// <note>An additional tick may elapse after removal, due to the multithreaded nature.</note>
        /// </returns>
        public IDisposable Tick(int tickTimeInSeconds, string service, Func <TickEvent> onTick)
        {
            var disposable = new TickDisposable(tickTimeInSeconds, service, onTick);

            lock (_timerLock) {
                if (_ticks == null)
                {
                    _ticks = new List <TickDisposable>();
                    _timer = new Timer(_ => ProcessTicks());
                    _timer.Change(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0));
                }
                _ticks.Add(disposable);
            }
            return(disposable);
        }
Esempio n. 2
0
 ///
 /// <summary>
 /// After <paramref name="tickTimeInSeconds" /> seconds, <paramref name="onTick" /> will be invoked.
 /// The resulting <see cref="TickEvent" /> is composed with the <paramref name="service" /> to generate an Event.
 /// </summary>
 /// <param name="tickTimeInSeconds">
 /// Number of seconds to wait before calling the event back.
 /// <note>Because only a single thread calls the events back, it may be called back sooner.</note>
 /// </param>
 /// <param name="service">Name of the service to send to Riemann</param>
 /// <param name="onTick">Function to call back after wait period</param>
 /// <returns>
 /// A disposable that, if called, will remove this callback from getting called.
 /// <note>An additional tick may elapse after removal, due to the multithreaded nature.</note>
 /// </returns>
 public IDisposable Tick(int tickTimeInSeconds, string service, Func<TickEvent> onTick)
 {
     var disposable = new TickDisposable(tickTimeInSeconds, service, onTick);
     lock(_timerLock) {
         if (_ticks == null) {
             _ticks = new List<TickDisposable>();
             _timer = new Timer(_=> ProcessTicks());
             _timer.Change(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0));
         }
         _ticks.Add(disposable);
     }
     return disposable;
 }