窗口程序异常退出
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 10000; i++)
{
panel1.Controls.Clear();
Panel p = new Panel();
p.BackColor = Color.Red;
p.Dock = DockStyle.Fill;
panel1.Controls.Add(p);
}
}
如上,执行10000个循环,程序会自动退出,无任何提示。
事件查看器有如下提示:
应用程序: TestMenuPop.exe
Framework 版本: v4.0.30319
说明: 由于未经处理的异常,进程终止。
异常信息: System.ComponentModel.Win32Exception
堆栈:
在 System.Windows.Forms.NativeWindow.CreateHandle(System.Windows.Forms.CreateParams)
在 System.Windows.Forms.Control.CreateHandle()
在 System.Windows.Forms.Control.get_Handle()
在 System.Windows.Forms.Control.CreateGraphicsInternal()
在 System.Windows.Forms.ThreadExceptionDialog..ctor(System.Exception)
在 System.Windows.Forms.Application+ThreadContext.OnThreadException(System.Exception)
在 System.Windows.Forms.Control.WndProcException(System.Exception)
在 System.Windows.Forms.Control+ControlNativeWindow.OnThreadException(System.Exception)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG ByRef)
在 System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr, Int32, Int32)
在 System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext)
在 System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, System.Windows.Forms.ApplicationContext)
在 System.Windows.Forms.Application.Run(System.Windows.Forms.Form)
在 TestMenuPop.Program.Main()
请教原因,谢谢。