473,403 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

timer is not working for file creation using c#

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..
Nov 8 '11 #1
0 1274

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: [ EuGeNe ] | last post by:
Hi all, I would like to write a script that downloads one file from a ftp server if the file creation date satisfy a condition. I can't figure out how to find from a ftp server what is the...
8
by: Brandon McCombs | last post by:
This may be the wrong group but I didn't see anything for VC++ so I'm trying here. I have a C++ book by Deitel and Deitel that says I can use fstream File("data.dat", ios::in | ios::out |...
3
by: SK | last post by:
I have a file. i get the creation time using File.GetCreationTime. then i go and delete that file. and then create it again and print the File.GetCreationTime. It is giving me the old creation...
1
dizyn
by: dizyn | last post by:
I want to create an xml using php and i want to save hashed password in it, Please tell me simplest way to do so. aboved mentioned error happend with i used this code for xml file creation. ...
0
by: rlynnridpath | last post by:
Hi, I'm getting the following error when trying to build my product with ClearCase on a Windows machine using Samba: File creation error - The volume for a file has been externally altered so...
1
by: zahidkhan | last post by:
Hi All, Any body has any idea abt this. I have to write a function which will take existing file name as an input parmeter and will return file creation time. I need to implement this function...
1
by: sujatharajan2003 | last post by:
Hi Everybody, I am new to this network. I am VB programmer. I have an issue in file creation in append mode. I have opened the file using open function in append mode. Ex: Open "D:\log.txt" For...
2
by: dhulapati | last post by:
I cant get the timer working with the windows service. I have the timer set to 3600 ms. It polls only for Start and Stop but not at intervals. The timer1.tick event handler is called at the...
6
by: sainiamit25 | last post by:
Hi, I want to parse a file and from some of the attributes of this file, i want to create another file using perl. Can anybody suggest me a way out? It would be great if i dont have to use any...
23
by: bc90021 | last post by:
Hi All, Thanks in advance for any and all help! I have this code: g = open(fileName, 'a') where fileName is defined before the line it's used in. It works fine when I use it outside a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.