Click to See Complete Forum and Search --> : loops and Close() error
andreshs1
February 22nd, 2006, 05:23 AM
Hello guys
I am trying to close a form from a loop, but for some reason it doesn't work
basically I use the this.Close() from inside the loop and the loop continues, why??
Thanks
Shuja Ali
February 22nd, 2006, 05:32 AM
The best way to do this should be to break from the loop and then close the Form.
andreshs1
February 22nd, 2006, 06:14 AM
Hello again Shuja
well, I break from the loop and then I return to the main method with a false, in the main method I check the return value and if is false then this.close()
but even so, the application continues running, :S
I am trully puzzle about this.
Why is that happening? isn't this.Close() meant to terminate the application by closing the main form?
this is the code
private void btnStart_Click(object sender, System.EventArgs e)
{
if(!getNumbers())
this.Close();
displayComparison();
}
Thanks
andreshs1
February 22nd, 2006, 06:21 AM
Hi,
I have sorted, basically the problem was that apparently, it doesn't just close the form, first of all executes till the end of the method, why is that?
well, what I did was to include the rest of the method on the if statement
private void btnStart_Click(object sender, System.EventArgs e)
{
if(!getNumbers())
this.Close();
else
displayComparison();
}
Although I have fixed, I would like to know why is acting like that, and what methods could be used instead of Close() for terminating applications.
Thanks
jmcilhinney
February 22nd, 2006, 06:48 AM
Place a return statement immediately after the call to Close if it may not be the last statement in the method.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.