Solved

# Timer problem

Posted on 1998-11-18
Medium Priority
232 Views
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...
0
Question by:sram
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 5
• 4
• 2
• +2

LVL 6

Expert Comment

ID: 1324938
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

LVL 2

Expert Comment

ID: 1324939
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

LVL 8

Expert Comment

ID: 1324940
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

LVL 6

Expert Comment

ID: 1324941
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

LVL 2

Expert Comment

ID: 1324942
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

LVL 8

Expert Comment

ID: 1324943
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 Comment

ID: 1324944
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

LVL 6

Expert Comment

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

Author Comment

ID: 1324946
No not necessary...
0

LVL 3

Expert Comment

ID: 1324947
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 Comment

ID: 1324948
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

LVL 3

Expert Comment

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

0

Author Comment

ID: 1324950
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 Comment

ID: 1324951
thresher_shark! answer the question and I will give you the points
sram
0

LVL 6

Accepted Solution

thresher_shark earned 120 total points
ID: 1324952
Oky doky.  Thanks.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messaâ€¦
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized â€¦
###### Suggested Courses
Course of the Month13 days, 10 hours left to enroll