Tono Nam
Tono Nam

Reputation: 36048

Create window like messagebox where code will continue to run once you close the window

I would like to create a window on the main thread so that it behaves like the messagebox window. In other words I am looking for something like:

var myView = new Views.MyWindow();
myView.Show(); // I want to wait here until myView is closed?

// continue execution once myView is closed

I know I could create a semaphore to achieve this and have the other window release the semaphore once it closes but how does the message box window manage to do it on the same thread?

Upvotes: 2

Views: 185

Answers (1)

Oscar Mederos
Oscar Mederos

Reputation: 29813

You have to use ShowDialog() instead of Show()

Quoting from MSDN:

When this method is called, the code following it is not executed until after the dialog box is closed.

the ShowDialog() method returns an bool? object. Using it, you will be able to know if the user just closed the window, clicked on the Accept button, etc:

var result = myView.ShowDialog();
if (result) {
    //do something here...
}

Upvotes: 3

Related Questions