In C#,
Suppose I am in a form, and I pressed a button I made to close it.
this.Close();
some_action(); //can I do this??
can I perform another action after I closed the form or does the thread die and everything after that is lost?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Depends on what you are trying to do and the context of the statement. If the form being closed is the main form which owns the message loop, you can’t do any UI related stuff (e.g. you can’t display another
MessageBox). If you are not doing it from another window (which doesn’t own the message loop), you could do anything (even UI related) as long as you aren’t manipulating the closed form object (you’ll getObjectDisposedExceptionjust like any disposed object).By the way, the thread doesn’t die as a result of
Close. Closing the main window causes the message loop to terminate and not the thread itself. For example, the following programwill display
Form2afterForm1is closed (using a newly created message loop). This proves that the thread is not dead.