最佳答案
我已经习惯了在 VisualStudio 中使用 WinForms 编程,但是我想尝试一下 WPF。
我在我的项目中添加了另一个窗口,叫做 Windows01。主窗口称为 MainWindow。在 public MainWindow()
构造函数之前,我声明 Windows01:
Window01 w1;
现在我实例化这个窗口:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
w1 = new Window01();
}
我有一个按钮的窗口显示: w1.ShowDialog();
。
这里“有趣”的事实是,如果我启动应用程序(使用调试)并在几秒钟后退出(我不在应用程序中做任何事情) ,Visual Studio 不会停止调试,就好像应用程序仍然在运行一样。
如果我将代码行 w1 = new Window01();
移动到按钮单击方法,这意味着刚好在 ShowDialog()
之上,Visual Studio 的工作正常——也就是说,当我退出应用程序时调试停止。
为什么会有这种奇怪的行为?