473,761 Members | 5,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Timing Question


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 (CheckForNewBat ches) 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(C heckForNewBatch es);
checkerTimer = new
Timer(timerTick ed,autoEvent,Mi lliSecondsToDel ay,3600000);
=====EndofConst ructor
// Should return the number of milliseconds to wait untill next hour
internal int MilliSecondsToD elay {
get {

if (startTime == DateTime.MinVal ue)
startTime = DateTime.Now;
if (startTime.Minu te != 0)
return (3600000 - (startTime.Minu te * 60000 -
startTime.Secon d * 1000));
else {
onHour = new DateTime(startT ime.Year,
startTime.Month , startTime.Day, startTime.Hour, 0, 0);
return 0;
}
}
}
private void CheckForNewBatc hes(Object sender){
///Do whatever
}
---
Best Regards
Amir

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
9 1755
Amir,

Instead of having your application perform this timing, why not just set
it up as a scheduled task on the machine? Have your application perform
only the logic to perform the tasks you need it to do (not the timing
logic), and then have the scheduled task manager run the task ever hour.
This way, you don't have to worry about it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Amir Ghezelbash" <am*******@hotm ail.com> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .

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 (CheckForNewBat ches) 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(C heckForNewBatch es);
checkerTimer = new
Timer(timerTick ed,autoEvent,Mi lliSecondsToDel ay,3600000);
=====EndofConst ructor
// Should return the number of milliseconds to wait untill next hour
internal int MilliSecondsToD elay {
get {

if (startTime == DateTime.MinVal ue)
startTime = DateTime.Now;
if (startTime.Minu te != 0)
return (3600000 - (startTime.Minu te * 60000 -
startTime.Secon d * 1000));
else {
onHour = new DateTime(startT ime.Year,
startTime.Month , startTime.Day, startTime.Hour, 0, 0);
return 0;
}
}
}
private void CheckForNewBatc hes(Object sender){
///Do whatever
}
---
Best Regards
Amir

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #2
Hi,
There is nothing wrong with your code. and there is nothing you can do to
solve it :)

You cannot be sure that your app will start running at EXACTLY 5:00:00 , at
that moment an event is send and processed later on, so it's normal it will
take a little longer to wait.

A similar thing if you follow Paldino's suggestions, in short WinXX is not a
real time OS.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Amir Ghezelbash" <am*******@hotm ail.com> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .

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 (CheckForNewBat ches) 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(C heckForNewBatch es);
checkerTimer = new
Timer(timerTick ed,autoEvent,Mi lliSecondsToDel ay,3600000);
=====EndofConst ructor
// Should return the number of milliseconds to wait untill next hour
internal int MilliSecondsToD elay {
get {

if (startTime == DateTime.MinVal ue)
startTime = DateTime.Now;
if (startTime.Minu te != 0)
return (3600000 - (startTime.Minu te * 60000 -
startTime.Secon d * 1000));
else {
onHour = new DateTime(startT ime.Year,
startTime.Month , startTime.Day, startTime.Hour, 0, 0);
return 0;
}
}
}
private void CheckForNewBatc hes(Object sender){
///Do whatever
}
---
Best Regards
Amir

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #3
hi thanks for your replies guys

but i canot use the schdeule taks due to the fact that this exe has to
be running all the time ...it does alot of things like managing a
webapplication Database, if i were to use windows schedule task manager
i have to create a new instance of the application every hour...which i
dont really want to do ..it would desotry my whole logic plus... windows
would run out of memory :P ....any other suggestions?
---
Best Regards
Amir

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #4
Amir,

There are really no other suggestions. You will have to calculate the
amount of time to wait from the time you set the timer property until the
next time you have to run a task.

Also, I don't see why your machine would run out of memory if you used a
task scheduler. Once the executable is done, the process disappears, and
memory is reclaimed by the OS.

If anything, you run a greater risk of running out of memory by having
your own continuous process run. If you are doing nothing but running tasks
on a timed basis, then the scheduled task manager is really the way to go.
No need to reinvent the wheel. Also, as Ignacio said, this is not a
real-time OS, so you won't be able to get it to execute EXACTLY at 5 PM.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Amir Ghezelbash" <am*******@hotm ail.com> wrote in message
news:OM******** **********@TK2M SFTNGP14.phx.gb l...
hi thanks for your replies guys

but i canot use the schdeule taks due to the fact that this exe has to
be running all the time ...it does alot of things like managing a
webapplication Database, if i were to use windows schedule task manager
i have to create a new instance of the application every hour...which i
dont really want to do ..it would desotry my whole logic plus... windows
would run out of memory :P ....any other suggestions?
---
Best Regards
Amir

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #5
Tell me why would sql not return anything when you run the query at 5:00:01
for instance?

Willy.

"Amir Ghezelbash" <am*******@hotm ail.com> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .

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 (CheckForNewBat ches) 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(C heckForNewBatch es);
checkerTimer = new
Timer(timerTick ed,autoEvent,Mi lliSecondsToDel ay,3600000);
=====EndofConst ructor
// Should return the number of milliseconds to wait untill next hour
internal int MilliSecondsToD elay {
get {

if (startTime == DateTime.MinVal ue)
startTime = DateTime.Now;
if (startTime.Minu te != 0)
return (3600000 - (startTime.Minu te * 60000 -
startTime.Secon d * 1000));
else {
onHour = new DateTime(startT ime.Year,
startTime.Month , startTime.Day, startTime.Hour, 0, 0);
return 0;
}
}
}
private void CheckForNewBatc hes(Object sender){
///Do whatever
}
---
Best Regards
Amir

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #6
Hi,

Then you are stuck with a window service, and accept that you will not get
executed at an exxact time, not even every 1 hour sharp, there will always
be a lag, depending of how busy your computer is.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Amir Ghezelbash" <am*******@hotm ail.com> wrote in message
news:OM******** **********@TK2M SFTNGP14.phx.gb l...
hi thanks for your replies guys

but i canot use the schdeule taks due to the fact that this exe has to
be running all the time ...it does alot of things like managing a
webapplication Database, if i were to use windows schedule task manager
i have to create a new instance of the application every hour...which i
dont really want to do ..it would desotry my whole logic plus... windows
would run out of memory :P ....any other suggestions?
---
Best Regards
Amir

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #7
ok guys thank you for all yoru responses

actually this gets me the excat time to the secnod
return ((59 - DateTime.Now.Mi nute) * 60 * 1000) + ((60 -
DateTime.Now.Se cond) * 1000);

thank you again

oh btw about that guy who asked why sql wouldnot return any thing is
becuase users only are allowed to set atime in formats of

5:00
5:15:00
5:30:00
5:45:00

so the seconds inside my sql table are always zero
if my time doesnot have a zero seconds. then my select statment wouldnot
return any thing

any way thanks again

---
Best Regards
Amir

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #8
That's a load of garbage Amir.

If you construct your SQL 'select' statement correctly it will pickup
anything you tell it too.

E.G.: Run at 5:00 AM or as soon as possible thereafter:

"select <select_list> from <table_name> where <date_column_na me> >= '" +
DateTime.Now.To String("HH") + ":00' and " +
"<date_column_n ame> < '" + DateTime.Now.Ad dHour(1).ToStri ng("HH") + ":00"

In the real world, the planet keeps turning even if a task that is supposed
to be started on the hour is not executed until a short time after the hour.
I have yet to see someone get fired because they were a second late in
starting a task.

When I need such finctionality, I tend to use a thread that iterates and at
the end of each iteration sleeps for, say, 100 milliseconds. Each time it
wakes I check to see if it needs to do something.

In this case the task would get started approxiamately 1 tenth of a second
after the hour and think that something similar would suit you purpose
admirably.

"Amir Ghezelbash" <am*******@hotm ail.com> wrote in message
news:e2******** ******@TK2MSFTN GP09.phx.gbl...
ok guys thank you for all yoru responses

actually this gets me the excat time to the secnod
return ((59 - DateTime.Now.Mi nute) * 60 * 1000) + ((60 -
DateTime.Now.Se cond) * 1000);

thank you again

oh btw about that guy who asked why sql wouldnot return any thing is
becuase users only are allowed to set atime in formats of

5:00
5:15:00
5:30:00
5:45:00

so the seconds inside my sql table are always zero
if my time doesnot have a zero seconds. then my select statment wouldnot
return any thing

any way thanks again

---
Best Regards
Amir

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #9
I would want to believe that you can manipulate the query to get the data that's stored in the database anytime you want.

In case you are not, why don't you setup the timer to fire the callback 5 mins before the actual time you wanted it to fire and then wait for the correct time to fire the query, this way you have a good chance of firing the query exactly at the time you want, maybe a couple of seconds here and there.

And use the Timer type implemented in the System.Threadin g namespace for a more accurate timer implementation.

HTH, Metallikanz!

"Amir Ghezelbash" <am*******@hotm ail.com> wrote in message news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .

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 (CheckForNewBat ches) 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(C heckForNewBatch es);
checkerTimer = new
Timer(timerTick ed,autoEvent,Mi lliSecondsToDel ay,3600000);


=====EndofConst ructor


// Should return the number of milliseconds to wait untill next hour
internal int MilliSecondsToD elay {
get {

if (startTime == DateTime.MinVal ue)
startTime = DateTime.Now;


if (startTime.Minu te != 0)
return (3600000 - (startTime.Minu te * 60000 -
startTime.Secon d * 1000));
else {
onHour = new DateTime(startT ime.Year,
startTime.Month , startTime.Day, startTime.Hour, 0, 0);
return 0;
}
}
}


private void CheckForNewBatc hes(Object sender){
///Do whatever
}
---
Best Regards
Amir

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1822
by: S. David Rose | last post by:
Hello All! I am new to Python, and wanted to know if I might ask you a question regarding timing. I want a main loop which takes photos from 8 different web-cams, each can be addressed by http://ip-addr/image.jpg. That's the easy part, but I want to have 2 cameras poll 3-times a second, 4 cameras poll 2 times a second, and the remaining 2 cameras poll once a second. I have found lots of info suggesting the use of threads for this, all...
10
2166
by: Greg Stark | last post by:
This query is odd, it seems to be taking over a second according to my log_duration logs and according to psql's \timing numbers. However explain analyze says it's running in about a third of a second. What would cause this? Is it some kind of postgresql.conf configuration failure? I have the same query running fine on a different machine. QUERY PLAN...
7
3769
by: jamie | last post by:
hey all, I am attempting to do motion control for a final project, but I have a concern.... For motion control, timing is everyting, the better it is, the better it works. Currently I am trying to use the timer function block to do a 10ms loop, but if I remember correctly.... that timing
1
2194
by: AVance | last post by:
Hi, I've come across this scenario in ASP.NET 1.1 with forms authentication where the forms auth doesn't seem to timeout correctly, nor redirect to the login page. I have done some testing, and I believe I've found a solution, but I would like some insight from Microsoft on whether the code I've implemented is correct, and why it is even working. Here is my scenario:
1
1421
by: Novice | last post by:
Hi all, I'm at my wit's end on trying to insert some timing code into the server side code that parses the hashed data contained in the hidden field being submitted to the server I've tried placing timing code in all of the following: Page_Load OnInit LoadViewState(object savedState) object SaveViewState()
3
1696
by: gregory_may | last post by:
I have an application where I am using a System Thread to capture the screen & Broadcast it to clients. Its "working", but the timing on the background thread gets wildly erratic at times. Some times, its right away, some times after 10 seconds. I have included the setup of the process and the outline of the Call Back Method. As posted, the callback method can be mildly erratic (only doing a debug.writeline) I am guessing up to an 80%...
2
3305
by: Steven D'Aprano | last post by:
The timeit module is ideal for measuring small code snippets; I want to measure large function objects. Because the timeit module takes the code snippet argument as a string, it is quite handy to use from the command line, but it is less convenient for timing large pieces of code or when working in the interactive interpreter. E.g. variations on this *don't* work: $ python Python 2.4.3 (#1, Jun 13 2006, 11:46:08)
15
2580
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to determine who needs to receive the text message then send the message to the address. Only problem is, the employee may receive up to 4 of the same messages because each thread gets the recors then sends the message. I need somehow to prevent...
4
2517
by: Thomas R. Hummel | last post by:
We are using SQL Server 2005. The SP in question is a fairly simple select statement. When the developers run their unit tests it is timing out (15 second timeout is set from their end). When I run the SP in a query window using the exact same parameters it takes less than a second to run. I've run profiler and turned up nothing there, including deadlocks. The SP does show as having a duration of 15 seconds though. I've also run the...
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9377
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8814
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.