# Timer problem

I have an application that uses two timers. I write to disk once in 5 mts. This works fine and writes data to disk every 5mts on certain machines and only on 1 machine writes at sometimes 2 somwtimes 3 mts. What does the settimer use to time itself? Please help...
###### Who is Participating?

Commented:
Oky doky.  Thanks.
0

Commented:
I think I may know the problem.  The number in the SetTimer function is 300000 right (5 minutes)?  That is too large.  You cannot use numbers greater than 65535 (65.535 seconds).  This means that you have to set the timer for something like 60 seconds, and then in the OnTimer function, use a static integer to count the number of minutes that have gone by.

like so:

SetTimer (1, 60000, NULL);

.

MyAppDlg::OnTimer (...)
{ static int counter = 0;
counter++;
if (counter == 5)
{ counter = 0;
// Place code here to have executed every 5 min.
}
}

0

Commented:
Actually, SetTimer takes an UINT and under Win32, a UINT is the same as a unsigned long. Thus the max would be 4294967295 seconds.

But under Windows 3.x, yes, the UINT max is 65535.

0

Commented:
SetTimer uses the PC clock tick (18.2 per second)

You may miss timer messages if the app is tied up rather than processing messages.  The usually effect is to have _longer_ intervals between WM_TIMER messages than you expect...so I can't explain your problem...unless you calculations are wrong (milliseconds)

5 minutes =  5 * 60  * 1000 = 300,000
0

Commented:
prasanth - Really?  Wow, I really am living in the past.  I used to program in DOS (wow!) and in DOS, an unsigned integer was 16 bits.  Is an "unsigned int" the same as an "unsigned long" or is a "UINT" just the same as an "unsigned long" ?
0

Commented:
thresher_shark - In Win32, both a long and an int are 32 bits.
A short is still 16 bits though.

sram - As Answers200 points out, an actual interval LONGER than your specified interval is possible. but a short interval... hmm. Could there be a third-party disk cache or something like that running on the one machine where you are having the problem?
0

Commented:
Incidentally the fact (almost) everything is 32 bits in Win32, seems to have produced a mini revival of the (sick) syndrome you see in many Unix C programs - using an "int" for everything

int x ; /* x is an int */
int p ; /* p is an int, but programmers users it for a pointer */
/* etc */

Any newbies who read this, don't fall into this trap.  Types are your friend..
0

Author Commented:
I have fixed the problem... I am on a 16 bit system hence I can fo as far as 65.5secs. But I have used a counter to solve the problem and also have resolved the multiple timer problem. Thank you anyway...

sram
0

Commented:
Should I answer then since that's what I said?
0

Author Commented:
No not necessary...
0

Commented:
necessary perhaps not but remember:
Experts earn points for the answers so if an Expert points you into the right direction you should give him the points
0

Author Commented:
I wish I could the screen that pulls up does not give me an option to grade the answer as A B C or D.
0

Commented:
Thats the reason why  thresher_shark asked you:
>>Should I answer then since that's what I said?<<

0

Author Commented:
I wish I could the screen that pulls up does not give me an option to grade the answer as A B C or D.
0

Author Commented:
thresher_shark! answer the question and I will give you the points
sram
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.