|
-
February 22nd, 2006, 06:23 AM
#1
loops and Close() error
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
Favourite Quotes
"In the first place, God made idiots. That was for practice. Then he made developers."
"Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done."
-
February 22nd, 2006, 06:32 AM
#2
Re: loops and Close() error
The best way to do this should be to break from the loop and then close the Form.
-
February 22nd, 2006, 07:14 AM
#3
Re: loops and Close() error
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
Code:
private void btnStart_Click(object sender, System.EventArgs e)
{
if(!getNumbers())
this.Close();
displayComparison();
}
Thanks
Favourite Quotes
"In the first place, God made idiots. That was for practice. Then he made developers."
"Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done."
-
February 22nd, 2006, 07:21 AM
#4
Re: loops and Close() error
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
Code:
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
Favourite Quotes
"In the first place, God made idiots. That was for practice. Then he made developers."
"Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done."
-
February 22nd, 2006, 07:48 AM
#5
Re: loops and Close() error
Place a return statement immediately after the call to Close if it may not be the last statement in the method.
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
|