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
Printable View
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
The best way to do this should be to break from the loop and then close the Form.
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
ThanksCode:
private void btnStart_Click(object sender, System.EventArgs e)
{
if(!getNumbers())
this.Close();
displayComparison();
}
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
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.Code:
private void btnStart_Click(object sender, System.EventArgs e)
{
if(!getNumbers())
this.Close();
else
displayComparison();
}
Thanks
Place a return statement immediately after the call to Close if it may not be the last statement in the method.