FileWatcher/code/src/TimerPlus.cs

54 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
using System.Threading;
using System.Threading.Tasks;
namespace FileWatcher
{
/// <summary>
/// DO NOT CAST TO A TIMER, always interact with this class directly. Start and Stop are not overridden.
/// </summary>
public class TimerPlus : System.Timers.Timer
{
private bool m_Running;
private DateTime m_Start;
private DateTime m_End;
public TimerPlus()
{
}
public TimerPlus(double interval)
: base(interval)
{
}
public void Start()
{
m_Running = true;
m_Start = DateTime.Now;
base.Start();
}
public void Stop()
{
m_End = DateTime.Now;
m_Running = false;
base.Stop();
}
public TimeSpan TimeElapsed
{
get { return m_Running ? DateTime.Now - m_Start : m_End - m_Start; }
}
public TimeSpan TimeRemaining
{
get { return TimeSpan.FromMilliseconds(Interval) - TimeElapsed; }
}
}
}