1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Timers;
- namespace LogoForceTestApp.Modules.MainModule.Models
- {
- public class ResettableTimer
- {
- private readonly Timer _timer;
- private ElapsedEventHandler _onIntervalElapsed;
- public event ElapsedEventHandler Elapsed
- {
- add
- {
- _onIntervalElapsed = (ElapsedEventHandler)Delegate.Combine(_onIntervalElapsed, value);
- }
- remove
- {
- _onIntervalElapsed = (ElapsedEventHandler)Delegate.Remove(_onIntervalElapsed, value);
- }
- }
- public ResettableTimer(double interval)
- {
- _timer = new Timer(interval);
- _timer.Elapsed += OnTimedEvent;
- }
- private void OnTimedEvent(object source, ElapsedEventArgs e)
- {
- //Console.WriteLine("The Elapsed event was raised at {0:HH:mm:ss.fff}", e.SignalTime);
- _onIntervalElapsed.Invoke(this, e);
- }
- public void Start()
- {
- _timer.Start();
- }
- public void Stop()
- {
- _timer.Stop();
- }
- public void Reset()
- {
- Stop();
- Start();
- }
- }
- }
|