Here is my problem ....
I am doing backup schedule every day (i.e) if any backup file is not created with in 24 hours
,I want to create new backup file(`executing backupdatabase() function`) .....
In addition to , I have used timer , `so that every hour it will be checked whether the file is created` or not....and after 24 hours it will created new file (`executing backupdatabase() function`)
File checking is done by using File.GetcreationTime....whether the file is created or not..
For that i have done like this...
public partial class BackupForm : Form
{
private static System.Timers.Timer _timer;
private Int32 _hours = 0;
private const Int32 RUN_AT = 10;
private void BackupForm_Load(object sender, EventArgs e)
{
var today = DateTime.Now;
_hours = (24 - (DateTime.Now.Hour + 1)) + RUN_AT;
_timer = new Timer { Interval = _hours * 60 * 60 * 1000 };
_timer.Elapsed += new ElapsedEventHandler(Tick);
_timer.Start();
}
void Tick(object sender, ElapsedEventArgs e)
{
_timer.Stop();
var name = "localhost";
const string path = @"C:\Creation\Name\backupdb\";
var listfiles = Directory.GetFiles(@"C:\Creation\Name\backupdb\", "backup-*.zip").ToList();
var files = listfiles.Select(Path.GetFileName).ToList();
var dt = DateTime.Now;
foreach (var file in files)
{
var creationtime = File.GetCreationTime(file);
var diff = DateTime.Now.Subtract(creationtime);
if (diff.Hours > 24 && diff.Days < 2 && creationtime.Month == dt.Month && creationtime.Year == dt.Year && name == "localhost" && _hours == 24)
{
backupDatabase();
}
else if (_hours != 24)
{
_hours = 24;
_timer.Interval = _hours * 60 * 60 * 1000;
}
}
_timer.Start();
}
}
But it does not working , it does not checking the file creation time and even it does not creating the file after 24 hours...
how to check the file with creation time along with timer for every one hour and after 24 hours how to create the file ....
any help that would very helpful..