Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timer in C

Status
Not open for further replies.

ratzp

Programmer
Dec 30, 2005
49
0
0
IN
how to set a timer in C which will call a user defined function after a specific interval of time specified by me.
 
Which operating system and compiler are you using?


--
 
Salem the operating system is Win 98 and compiler is TurboC
Hope to see reply soon
 
Are you planning to be doing anything else whilst waiting for the time to elapse?

Since you're using TurboC, which can only create DOS programs, and DOS is the worst operating system for writing anything with any asynchronous behavior, you're in for a hard time.

--
 
You will need to write your program as TSR that will be triggered by the clock tick. Are you familiar with TSR programming?

Walid Magd (MCP)

The primary challenge of every software development team is to engineer the illusion of simplicity in the face of essential complexity.
-Grady Booch
 
... or instead of a full-blown TSR, if the user-defined call is only to be made while your application is running, write an interrupt handler for the 18-times a second user interrupt in DOS, and make your handler keep an eye open for the time and call the correct function.

But do remember that when the call is made, the processor may not have been handling your application, so the data segment may be wrong, the stack may be wrong (or even very, very small) etc.
 
Do you have to daisy chain the timer interrupt to avoid screwing up the clock?
 
Good point. Back in the old days it was important to daisy-chain any interrupt you diverted, because if you wanted to use it, who knows who else might also have wanted to use it...

But nowadays I can't imagine many people running a DOS environment with several applications. The nice thing about windows dos-boxes is that they lead an independant confined existance, and what goes on in them shouldn't mess up anything else after they're closed.
 
Well I use cygwin compiler, I recommend it. Umm I don't know if it will work without cygwin but ex. sleep(5); would make the program stop for 5 seconds before continuing. Again I think that is a cygwin only command, but good luck.
 
Switch to another compiler, why are you keep using TurboC on Windows 98.
Than use function SetTimer to set the timer and catch the WM_TIMER message Windows will send after the timer will expire. After finishing, kill the timer with KillTimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top