You probably just want to use Timer
. A sample code is something like this
var timer = new Timer(TimerTick, null, TimeSpan.Zero, new TimeSpan(0, 0, 0, 1));
int lastMinute = 1;
void TimerTick(object state)
{
var minute = DateTime.Now.Minutes;
if (minute != lastMinute && minute % 5 == 0)
{
lastMinute = minute;
//Check the .txt file
}
}
As Thorsten Dittmar pointed out, yes you probably want to use System.Timers.Timer
than System.Threading.Timer
. Timers.Timer is thread-safe
too.
According to one of the answers from found here
The specific difference appears to be that System.Timers.Timer is geared towards multithreaded applications and is therefore thread-safe via its SynchronizationObject property, whereas System.Threading.Timer is ironically not thread-safe out-of-the-box.
I don't believe that there is a difference between the two as it pertains to how small your intervals can be.
There is also a link for a comprehensive explanation of timers.