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
  • Learn & ask questions
Solved

Timer problem

Posted on 1998-11-18
15
229 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to retreive data from .TFS file exported by DVR 8 217
bobThere java chalenge 45 94
VBA "SendKeys" Syntax for Multiple Keystrokes 7 117
mapBully challenge 6 152
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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

791 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