Scheduled Task To Turnover Files at Midnight Unpredictable

  • Thread starter Thread starter DisplayNamePaul
  • Start date Start date
D

DisplayNamePaul

Guest
Hello

I have an application which processes data to XML files. The source of the XML comes from two files, an A file and a B file inside a compare folder. When changes are detected between them it creates a file of differences (deltas.csv) where it only reports the latest changes.

At midnight is when the business wants to start a new day. So I have a Windows Task scheduled every fifteen minutes. I'm using a custom TimeRange class to trigger the file turnover.

public class TimeRange
{
public static bool NowTimeWithin0000_0015{ get; set; }

public TimeRange()
{
NowTimeWithin0000_0015 = CurrentTimeWithinMidnightAnd15MinsPast();
}

private bool CurrentTimeWithinMidnightAnd15MinsPast()
{
DateTime now = DateTime.Now;
DateTime CurrentTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 00);
DateTime TargetMin = new DateTime(now.Year, now.Month, now.Day, 00, 05, 00);
DateTime TargetMax = new DateTime(now.Year, now.Month, now.Day, 00, 15, 00);
bool answer = ((CurrentTime >= TargetMin) && (CurrentTime <= TargetMax)) ? true : false;
return answer;
}
}

When the Task is within this range (0005 to 0015, allowing five minutes to include the last run of the day before midnight), a method is supposed to clear out the compare folder files and start fresh. My issue is after midnight, the logs show execution times are no longer in multiples of 15.

Log execution times - (previous day 23:45), (new log) 00:00, 00:18, 00:33 and so on.

This makes the Task unpredictable therefore, the files never get cleared out because it is outside the range of my class.

I'm think about creating a new separate task just to delete the files at 00:05.

Have you ever encountered anything like this?

What would be the best way to ensure the compare folder gets cleared out at midnight?

Thanks

Continue reading...
 
Back
Top