我想在主线程上创建一个窗口,使其行为类似于 messagebox
窗口。换句话说,我正在寻找类似的东西:
var myView = new Views.MyWindow();
myView.Show(); // I want to wait here until myView is closed?
// continue execution once myView is closed
我知道我可以创建一个信号量来实现此目的,并让另一个窗口在关闭后释放信号量,但是消息框窗口如何设法在同一线程上执行此操作?
最佳答案
您必须使用ShowDialog()
而不是 Show()
引自MSDN:
When this method is called, the code following it is not executed until after the dialog box is closed.
ShowDialog()
方法返回一个 bool?
对象。使用它,您将能够知道用户是否刚刚关闭了窗口、单击了“接受”按钮等:
var result = myView.ShowDialog();
if (result) {
//do something here...
}
关于c# - 创建类似消息框的窗口,关闭窗口后代码将继续运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15259839/