在以下代码中,
Form1
打开了另外两个Form
,然后关闭了其中一个。结果是第二个子窗体也被关闭了。为什么会这样呢?public partial class Form1 : Form
{
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer { Interval = 2000 };
public Form1()
{
InitializeComponent();
ShowForm3();
(new Form2()).ShowDialog();//If this is changed to 'Show' - it doesn't get closed.
}
void ShowForm3()
{
Form3 f3 = new Form3();
f3.Show();
timer.Tick += (sender, e) => f3.Close();
timer.Start();
}
}
Form2
和Form3
是默认的VS表单。
(另外:这是原始代码的简化版本。在原始代码中,当在Visual Studio中执行时(无论是Debug还是Release),不会发生这种情况。只有当安装为ClickOnce应用程序后,即使我只是点击AppData文件夹下的可执行文件,它才会发生。(也许是代码中的其他部分在从VS中执行时阻止了它的发生,但我还没有找到具体原因。)什么可能引起这种差异?Maybe clickonce中存在某种优化,在常规Release模式下没有做到?)
Reflector
的时候了。 - Sriram Sakthivel