Solved

Timer problem

Posted on 1998-11-18
15
225 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

by:thresher_shark
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:thresher_shark
Comment Utility
Should I answer then since that's what I said?
0
 

Author Comment

by:sram
Comment Utility
No not necessary...
0
 
LVL 3

Expert Comment

by:Norbert
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Oky doky.  Thanks.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 122
Host to IP 7 73
canBalance challenge 34 65
Detect file exist or not 3 76
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now