Ending Button1 code from Button2 
Author Message
 Ending Button1 code from Button2

I am using VC++.NET and I have code that runs on a form when button 1(start
button) is pressed.  This code has a loop in it that will cause it to
continue to run until a flag (stop_flag) is turned on.  I would like to have
this flag turned on when button 2(stop button) is pressed.

Problem is that when this code under button 1 is running the form does not
allow me to click anything (its like its frozen) and I can not stop the code
from running.

The code stops just fine when I test for a key event "k" (kill), but it will
not allow me to press the stop button (button 2) while the code under button
1 is running and that is essentially what I would like to do.

Any Ideas?

Delali



Mon, 10 Jan 2005 02:58:21 GMT  
 Ending Button1 code from Button2
Maybe if you  start a new Thread for the loop?


Quote:
> I am using VC++.NET and I have code that runs on a form when button
1(start
> button) is pressed.  This code has a loop in it that will cause it to
> continue to run until a flag (stop_flag) is turned on.  I would like to
have
> this flag turned on when button 2(stop button) is pressed.

> Problem is that when this code under button 1 is running the form does not
> allow me to click anything (its like its frozen) and I can not stop the
code
> from running.

> The code stops just fine when I test for a key event "k" (kill), but it
will
> not allow me to press the stop button (button 2) while the code under
button
> 1 is running and that is essentially what I would like to do.

> Any Ideas?

> Delali



Mon, 10 Jan 2005 03:16:05 GMT  
 Ending Button1 code from Button2
sorry but I am new to this, I am not sure how do do this could you explain,
or point me to a tutorial?

Delali

Quote:
> Maybe if you  start a new Thread for the loop?



> > I am using VC++.NET and I have code that runs on a form when button
> 1(start
> > button) is pressed.  This code has a loop in it that will cause it to
> > continue to run until a flag (stop_flag) is turned on.  I would like to
> have
> > this flag turned on when button 2(stop button) is pressed.

> > Problem is that when this code under button 1 is running the form does
not
> > allow me to click anything (its like its frozen) and I can not stop the
> code
> > from running.

> > The code stops just fine when I test for a key event "k" (kill), but it
> will
> > not allow me to press the stop button (button 2) while the code under
> button
> > 1 is running and that is essentially what I would like to do.

> > Any Ideas?

> > Delali



Mon, 10 Jan 2005 03:23:38 GMT  
 Ending Button1 code from Button2
Well if your are using managed extensions should be similar to C#:
using System.Threading;

private Thread        m_threadForTheLoop            = null;

private void button1_Click(object sender, EventArgs e){
    m_theadForTheLoop = new Thread(new ThreadStart(MyLoopProcedure));
    m_threadForTheLoop.Start();

Quote:
}

private void MyLoopProcedure(){
//    Check for Flag & When finish then
    m_threadForTheLoop.Abort();

Quote:
}



Quote:
> sorry but I am new to this, I am not sure how do do this could you
explain,
> or point me to a tutorial?

> Delali


> > Maybe if you  start a new Thread for the loop?



> > > I am using VC++.NET and I have code that runs on a form when button
> > 1(start
> > > button) is pressed.  This code has a loop in it that will cause it to
> > > continue to run until a flag (stop_flag) is turned on.  I would like
to
> > have
> > > this flag turned on when button 2(stop button) is pressed.

> > > Problem is that when this code under button 1 is running the form does
> not
> > > allow me to click anything (its like its frozen) and I can not stop
the
> > code
> > > from running.

> > > The code stops just fine when I test for a key event "k" (kill), but
it
> > will
> > > not allow me to press the stop button (button 2) while the code under
> > button
> > > 1 is running and that is essentially what I would like to do.

> > > Any Ideas?

> > > Delali



Mon, 10 Jan 2005 04:33:51 GMT  
 Ending Button1 code from Button2
As your code hold CPU, it's no way for your application to receive windows
message, or paint it's UI. In your situation, you should try to use
muti-thread. Running your code in a background thread, so your application
won't be frozen.

Thanks
Lifeng

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> I am using VC++.NET and I have code that runs on a form when button
1(start
> button) is pressed.  This code has a loop in it that will cause it to
> continue to run until a flag (stop_flag) is turned on.  I would like to
have
> this flag turned on when button 2(stop button) is pressed.

> Problem is that when this code under button 1 is running the form does not
> allow me to click anything (its like its frozen) and I can not stop the
code
> from running.

> The code stops just fine when I test for a key event "k" (kill), but it
will
> not allow me to press the stop button (button 2) while the code under
button
> 1 is running and that is essentially what I would like to do.

> Any Ideas?

> Delali



Wed, 12 Jan 2005 04:31:16 GMT  
 Ending Button1 code from Button2
Try Placing Application.DoEvents() in your loop


Quote:
> I am using VC++.NET and I have code that runs on a form when button
1(start
> button) is pressed.  This code has a loop in it that will cause it to
> continue to run until a flag (stop_flag) is turned on.  I would like to
have
> this flag turned on when button 2(stop button) is pressed.

> Problem is that when this code under button 1 is running the form does not
> allow me to click anything (its like its frozen) and I can not stop the
code
> from running.

> The code stops just fine when I test for a key event "k" (kill), but it
will
> not allow me to press the stop button (button 2) while the code under
button
> 1 is running and that is essentially what I would like to do.

> Any Ideas?

> Delali



Wed, 12 Jan 2005 17:40:04 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. How to get "Button1.Text"?

2. no intellisense on button1

3. End of the year code metrics

4. Windowed Front End To C code

5. Remove Cancel Button - Thread Ends with Code 2

6. Missing */ at the end of a comment f______ over code

7. Need utility to put code at beginning and end of functions

8. how do i place an end of string char at the end of a string

9. Loosing Memory when Start end ends an Dialog

10. What is end after strtol("0x", &end, 0)?

11. detecting the end of form resizing ?

12. stay at end of listview ??

 

 
Powered by phpBB® Forum Software