A
Amir Ghezelbash
Hey every body i had a question
i am in process of writing an application, where this application needs
to check the database on hourly bases to see if they are any information
that are needed to be processed in the next upcoming hour
so my application has to to connect to data base right on (for example)
5:00:00 then check all the jobs that are due on
5:00:00
5:15:00
5:30:00
5:45:00
now i have no problem connecting to database and getting the list of
jobs that are due on that upcoming hour...my question is in timing
i want my application to fire a method called (CheckForNewBatches) on
each hour, which it does,,,but if my application starts on for example
4:30:27 i want it to wait till next hour which would 5:00:00 (excatly
other wise sql wouldnot return any thing) so even seconds should be
zero. so on new Timer method i have to give it the number of
milliseconds to wait to next hour..but i always get a wrong hour..for
example if i start my application at 4:30 the method wouldnot fire till
5:00:58 which is not what i want ..i want it to be right on
5:00:00....can some one tell what they see is wrong with my code
so in my consturctor i wrote something like that
autoEvent = new AutoResetEvent(false);
timerTicked = new TimerCallback(CheckForNewBatches);
checkerTimer = new
Timer(timerTicked,autoEvent,MilliSecondsToDelay,3600000);
=====EndofConstructor
// Should return the number of milliseconds to wait untill next hour
internal int MilliSecondsToDelay {
get {
if (startTime == DateTime.MinValue)
startTime = DateTime.Now;
if (startTime.Minute != 0)
return (3600000 - (startTime.Minute * 60000 -
startTime.Second * 1000));
else {
onHour = new DateTime(startTime.Year,
startTime.Month, startTime.Day, startTime.Hour, 0, 0);
return 0;
}
}
}
private void CheckForNewBatches(Object sender){
///Do whatever
}
i am in process of writing an application, where this application needs
to check the database on hourly bases to see if they are any information
that are needed to be processed in the next upcoming hour
so my application has to to connect to data base right on (for example)
5:00:00 then check all the jobs that are due on
5:00:00
5:15:00
5:30:00
5:45:00
now i have no problem connecting to database and getting the list of
jobs that are due on that upcoming hour...my question is in timing
i want my application to fire a method called (CheckForNewBatches) on
each hour, which it does,,,but if my application starts on for example
4:30:27 i want it to wait till next hour which would 5:00:00 (excatly
other wise sql wouldnot return any thing) so even seconds should be
zero. so on new Timer method i have to give it the number of
milliseconds to wait to next hour..but i always get a wrong hour..for
example if i start my application at 4:30 the method wouldnot fire till
5:00:58 which is not what i want ..i want it to be right on
5:00:00....can some one tell what they see is wrong with my code
so in my consturctor i wrote something like that
autoEvent = new AutoResetEvent(false);
timerTicked = new TimerCallback(CheckForNewBatches);
checkerTimer = new
Timer(timerTicked,autoEvent,MilliSecondsToDelay,3600000);
=====EndofConstructor
// Should return the number of milliseconds to wait untill next hour
internal int MilliSecondsToDelay {
get {
if (startTime == DateTime.MinValue)
startTime = DateTime.Now;
if (startTime.Minute != 0)
return (3600000 - (startTime.Minute * 60000 -
startTime.Second * 1000));
else {
onHour = new DateTime(startTime.Year,
startTime.Month, startTime.Day, startTime.Hour, 0, 0);
return 0;
}
}
}
private void CheckForNewBatches(Object sender){
///Do whatever
}