Solved Program freezing during loop

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Syperus

RTFM
Meme Tier VIP
Dank Tier Donator
Oct 29, 2012
432
2,638
7
Sup everyone. Aight I've been hesitant on creating this thread, but I'm all out of ideas. I've been having problems with my program, trainer I've been working on, freezing up when I start a while loop. It still works as intended, but the program itself freezes. My last resort was to try using Fleep's system check using clock(), but i still get the same effect. Here's the code i put in a checkbox checkedchanged function
C++:
bool timerstate = false;
int lapse = clock();

if (cb1->Checked)
{
   timerstate = true;
				 
   while(timerstate != false)
      {
         if(clock() - lapse > 5000)
            {
                 //memory code ect..
                 lapse = clock();
					 
             } 
				 
        }
					 
 }
else
{
      timerstate = false;
}
I set it to 5000(5 seconds) to make sure it wasn't getting thrown into an infinite loop. So can anyone see anything wrong with this?

My info:
Compiler: Visual Studio 2010 Ultimate
Operating System: Windows 7 64bit
Memory: 8gb
 

c5

Kim Kong Trasher
Dank Tier VIP
Dank Tier Donator
Jul 19, 2012
1,188
12,638
76
you never exit yourloop

HOW DO I EXIT ??? CONFUZZLED!
Keyword
C++:
break
is the answer
 
Last edited by a moderator:

squeenie

Hacker
Meme Tier VIP
Dank Tier Donator
Mar 6, 2013
677
5,478
37
Shouldn't lapse maybe += clock() instead of =?
 
Last edited:

Chuck E

Coder
Dank Tier Donator
Nobleman
Jan 2, 2013
122
588
1
Excuse me for possibly being silly here, but presumably you are setting timerstate to false (= exit while loop) somewhere within that While loop (once a certain condition is true of course) ?

So within the while loop, the timer is reset every 5 seconds. What is supposed to trigger it exiting the loop ?
 
Last edited:

Syperus

RTFM
Meme Tier VIP
Dank Tier Donator
Oct 29, 2012
432
2,638
7
Excuse me for possibly being silly here, but presumably you are setting timerstate to false (= exit while loop) somewhere within that While loop (once a certain condition is true of course) ?

So within the while loop, the timer is reset every 5 seconds. What is supposed to trigger it exiting the loop ?
I'm calling it within a checkbox_checkedchange function call. When the box is checked it starts the timer. When the checkbox is unchecked it sets the timerstatus function to false. So during the while loop every time it loops it checks to see if timerstatus is true or false.
 

Chuck E

Coder
Dank Tier Donator
Nobleman
Jan 2, 2013
122
588
1
Never mind me, I just can't see how that exits the while loop after the first time it enters it. It's not going to take anymore input from the checkbox, because it's wizzing around in that loop.

Sorry, my mind is going over and over here, attempting to see the logic from different angles.

I love puzzles, I'll look again at this tomorrow when I have a fresh head :)

Hmm, hang on...
 

Chuck E

Coder
Dank Tier Donator
Nobleman
Jan 2, 2013
122
588
1
C++:
bool timerstate = false;int lapse = clock();




if (cb1->Checked)// CHECKBOX IS CHECKED
{
   timerstate = true;
                 
   while(timerstate != false)  // keep on looping until timerstate is set to false
      {
         if(clock() - lapse > 5000)  // current time minus our start time, has 5 seconds passed?
            {                                                        // Yep, it has
                 //memory code ect..
                 lapse = clock(); // reset timer 
                     
             } 
                 
        } // continue looping - HOW DO I EXIT ??? CONFUZZLED! 
                     
 }
else// CHECKBOX IS NOT CHECKED
{
      timerstate = false;
}
Man, I thought Crypt was the one who set coding challenges here !

You've flummoxed me, lol. You bad person ;)

I'll look at this again tomorrow, and no doubt will have a D'oh moment :)
 

Radobot

Newbie
Full Member
Dec 5, 2012
13
182
0
From my personal experience I know that loop running on same thread as GUI will always freeze no matter what. Only way that worked for my was to use multiple threads (with working "timerstate" check to stop).
 

cpprogrammer

Newbie
Jul 12, 2013
4
152
0
C++:
bool timerstate = false;
int lapse = clock();
int TIME = 0;

if (cb1->Checked)
{
   timerstate = true;
				 
   while(timerstate != false && TIME < 5001)
      {
         if(clock() - lapse > 5000)
            {
                 //memory code ect..
                 lapse = clock();
                 TIME = TIME + 1; /*You Can Also Say TIME += 1*/
					 
             } 
				 
        }
					 
 }
else
{
      timerstate = false;
}
 
Last edited:
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods League of Legends Accounts