Solved

Timer problem

Posted on 1998-11-18
15
230 Views
Last Modified: 2013-11-20
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
Comment
Question by:sram
  • 5
  • 4
  • 2
  • +2
15 Comments
 
LVL 6

Expert Comment

by:thresher_shark
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.
  }
}

If you have any further questions, please don't hesitate to ask.
0
 
LVL 2

Expert Comment

by:prasanth
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

by:Answers2000
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:thresher_shark
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

by:prasanth
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

by:Answers2000
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

by:sram
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

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

Author Comment

by:sram
ID: 1324946
No not necessary...
0
 
LVL 3

Expert Comment

by:Norbert
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

by:sram
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

by:Norbert
ID: 1324949
Sure. at moment there is no answer so if you think  thresher_shark shoud earn the points ask him to answer the question - you can only grade answers not comments.
Thats the reason why  thresher_shark asked you:
>>Should I answer then since that's what I said?<<

0
 

Author Comment

by:sram
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

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

Accepted Solution

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replacement selected text 2 67
Prevent this page from creating additional dialogs. 3 727
Smart Camera scanning and reading information 3 122
sum13 challenge 24 135
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question