First, why are you creating a winform app? This should be a windows service so that it runs even when there is no user logged onto the system.
Second, you should use a thread to perform the task, or even a BackgroundWorker object.
private void BackupScheduleThread()
{
Thread backupThread = null;
DateTime now = DateTime.Now;
DateTime nextBackup = new DateTime(now.Year, now.Month, now.Day, 0, 1, 0, DateTimeKind.Local);
if (now > nextBackup)
{
nextBackup = nextBackup.AddDays(1);
}
do
{
if (now == nextBackup)
{
nextBackup.AddDays(1);
backupThread = new Thread(new ThreadStart(BackupFilesThread));
backupThread.Start();
}
now = DateTime.Now;
Thread.Sleep(1000);
} while (true);
}
private void BackupFilesThread()
{
}
To start the ball rolling, just do this:
Thread scheduleThread = new Thread(new ThreadStart(BackupScheduleThread));
scheduleThread.Start();
I referenced a tip/trick in the code above regarding my DateTime extension method that allows you to compare any part of a two dateTime objects for equality. This tip/trick removes the need to make sure ALL of the fiels are the same when they don't actually matter, such as the seconds and milliseconds. You can get the code here:
Partial DateTime Object Equality[
^]
Once you've implemented this, you will have isolated the scheduling from the act of creating the file.