I have been asked to add a pause to an existing C++ program.
The user does not want to use the Windows builtin scheduler for reasons they won't share with me.
Is the correct way of doing this something like:-
void Sleep(10000);
Printable View
I have been asked to add a pause to an existing C++ program.
The user does not want to use the Windows builtin scheduler for reasons they won't share with me.
Is the correct way of doing this something like:-
void Sleep(10000);
Define "pause".
Note that thiswill freeze your App. So its GUI will be completely "dead" for the 10 seconds and it would be at least surprised the users!Code:Sleep(10000);
Is it what you want? :confused:
Or you can send your app to a loop for 10 sec
for(int i = 0; i < 1000000; i++) // A basic for loop
or :
#define DELAY 128000 // increase the delay value if you wish
void delay(void);
void delay(void)
{
long int t;
for (t=1; t< DELAY ; t++ )
}
QUOTE=lio_cs;1861155]Or you can send your app to a loop for 10 sec
for(int i = 0; i < 1000000; i++) // A basic for loop
[/QUOTE]Well, why do you think that this loop will be executed for exactly 10 seconds? :confused: :rolleyes:[
And how exactly has OP to *increase* this magic 128000 number to get exactly 10 seconds on any user PC? :confused:
:thumbd:
Is your program a commandline program or does it has a GUI ?Quote:
I have been asked to add a pause to an existing C++ program.
Well, why do you think that this loop will be executed for exactly 10 seconds? :confused: :rolleyes:[
And how exactly has OP to *increase* this magic 128000 number to get exactly 10 seconds on any user PC? :confused:
:thumbd:[/QUOTE]
ok this will cause a 10 sec delay predefined by the programmer (DELAY)Code:#include <stdio.h>
#define DELAY 2560000000
struct my_time{
int hours;
int minutes;
int seconds;
};
void display(struct my_time *t);
void update(struct my_time *t);
void delay(void);
int main(void)
{
struct my_time systime;
systime.hours = 0;
systime.minutes = 0;
systime.seconds = 0;
for(;;)
{
update(&systime);
display(&systime);
}
return 0;
}
void update(struct my_time *t)
{
t->seconds++;
if(t->seconds==60)
{
t->seconds = 0;
t->minutes++;
}
if(t->minutes==60)
{
t->minutes = 0;
t->hours++;
}
if(t->hours==24) t->hours = 0;
delay();
}
void display(struct my_time *t)
{
printf("%02d:", t->hours);
printf("%02d:", t->minutes);
printf("%02d:\n", t->seconds);
}
void delay(void)
{
unsigned long int t;
for(t=1;t<DELAY;t++);
}
As Victor said, he needs to define pause and give more information about his app. Whatever it means, I believe it's relatively safe to say the solution doesn't lie in a busy/wait loop.
But it is what OP seemed to want to implement using Sleep(10000) which will freeze the current thread for exactly 10 seconds:
Well, I don't have enogh time to test your code; I just hope it will work...
The only question is: why waste time to develop/write/test some code that is supposed to do exactly the same as Sleep does?!
Besides. this code would just unusefully load CPU!