0

Why this first code works

MessageBox.Show("No Applicants\nFirst Add applicants with dataentryaccount");
MainWindow mw = new MainWindow();
mw.Show();
this.Close();

But this second code doesn't show the mw window

    MessageBox.Show("No Applicants\nFirst Add applicants with dataentryaccount");
MainWindow mw = new MainWindow();
this.Close();
mw.Show();

Although when debugged Line by Line all these lines are executed.

5
  • because you are closing the main program window before you show next window Commented Feb 27, 2016 at 6:26
  • But When debugged Line by line, the lines do execute? How will you justify that Commented Feb 27, 2016 at 6:31
  • It has to exit the current procedure which is called.. Commented Feb 27, 2016 at 6:32
  • I am still not getting it. Afterall it is executing Commented Feb 27, 2016 at 6:33
  • Honestly - How aren't you getting an ObjectDisposedException in both examples. Commented Feb 27, 2016 at 6:49

1 Answer 1

1

The EventHandler or procedure of the current execution block has some more code to execute.
You have not called return to stop the execution of the current procedure.

Close() is just another function which will not delete the form immediately. So it continues the execution of the current code.

Please check this answer for more details.

Sign up to request clarification or add additional context in comments.

1 Comment

Hmmm, So you mean that the new window would be created, But because of it having no more reference it will eventually be disposed by the garbage collector

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.