|
-
Mar 3rd, 2003, 09:05 AM
#1
Thread Starter
Registered User
Bout timers/interrupts
I want to make a program that will execute a function after 10 minutes. I mean along the process it will pause after ten minutes then execute a certain function. After execution it will resume the other process then count another 10 min. I tried using the delay(); and sleep(); function but it didnt worked. Is there any function that would be this possible?
ex
#include <stdio.h>
main()
{
clrscr();
/ * start counting for 10 minutes then execute a certain fxn*/
/* resume where it stopped */
}
-
Mar 3rd, 2003, 10:05 AM
#2
Hyperactive Member
IIRC, sleep() is in milliseconds, so 10 minutes would be sleep(600000);
If the problem isn't this, please state the problem clearly instead of saying "it didnt worked."
-
Mar 3rd, 2003, 01:44 PM
#3
Frenzied Member
You could also use the GetTickCount api.. this example pauses for 10 seconds and then quits:
Code:
#include <windows.h>
int main(){
DWORD start = GetTickCount();
for(;;)
if((GetTickCount() - start) > 10000)
break;
return 1;
}
Alternativly you could use the time functions or as said above, the sleep function...
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Mar 4th, 2003, 08:59 AM
#4
Monday Morning Lunatic
That code will just go round and round and round at 100% CPU.
Under Windows, calling Sleep(0) will tell the scheduler you don't want any more of your time-slice, hence you can get away with:
Code:
#include <windows.h>
int main() {
DWORD start = GetTickCount();
for(;;) {
if((GetTickCount() - start) > 10000)
break;
Sleep(0);
}
return 0; // return 0 for normal exit, 1 is an error condition
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 4th, 2003, 10:18 AM
#5
Frenzied Member
Thanks for correcting me mike, didn't know about the sleep(0) thing.. ah and also, I always mix up return 1 and return 0 this was the last time hehe (nullrmal )
Last edited by Jop; Mar 4th, 2003 at 10:23 AM.
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Mar 5th, 2003, 09:46 AM
#6
Thread Starter
Registered User
Thanks guys! Ill try this one... I'll keep in touch...
-
Mar 7th, 2003, 02:57 PM
#7
If you're already using Sleep, why not simply sleep for 8000 ticks and then enter a fast loop? This way you don't even start CPU shifts.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|