Winform 创建窗口句柄时出错
报错处的代码
frm.MdiParent = this;
frm.WindowState = FormWindowState.Maximized;
frm.Show();//出错地点
只是偶尔出错,有时候。
下面是详细的报错信息
未处理 System.OutOfMemoryException
Message="创建窗口句柄时出错。"
Source="System.Windows.Forms"
StackTrace:
在 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
在 System.Windows.Forms.Control.CreateHandle()
在 System.Windows.Forms.Form.CreateHandle()
在 System.Windows.Forms.Control.get_Handle()
在 System.Windows.Forms.Form.SetVisibleCore(Boolean value)
在 System.Windows.Forms.Control.Show()
在 Win.frmMain.WinOpen(Form frm) 位置 E:\Visual Studio 2008\Projects\LiveSW\Win\Admin\frmMain.cs:行号 91
在 Win.frmMain.签单周报_Click(Object sender, EventArgs e) 位置 E:\Visual Studio 2008\Projects\LiveSW\Win\Admin\frmMain.cs:行号 292
在 DevComponents.DotNetBar.BaseItem.RaiseClick(eEventSource source)
在 DevComponents.DotNetBar.BaseItem.InternalMouseUp(MouseEventArgs objArg)
在 DevComponents.DotNetBar.PopupItem.InternalMouseUp(MouseEventArgs objArg)
在 DevComponents.DotNetBar.ButtonItem.InternalMouseUp(MouseEventArgs objArg)
在 DevComponents.DotNetBar.MenuPanel.OnMouseUp(MouseEventArgs e)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 DevComponents.DotNetBar.MenuPanel.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(ApplicationContext context)
在 Win.Program.Main() 位置 E:\Visual Studio 2008\Projects\LiveSW\Win\Program.cs:行号 31
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException: System.NullReferenceException
Message="未将对象引用设置到对象的实例。"
Source="System.Windows.Forms"
StackTrace:
在 System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
在 System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
在 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
InnerException:
位置 E:\Visual Studio 2008\Projects\LiveSW\Win\Program.cs:行号 31
这个地方的代码:
private static ApplicationContext context;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
frmSplash sp = new frmSplash();
sp.Show();
context = new ApplicationContext();
context.Tag = sp;
Application.Idle += new EventHandler(Application_Idle);
Application.Run(context);//这个地方就是详细报错的31行
}
//初始化等待处理函数
private static void Application_Idle(object sender, EventArgs e)
{
Application.Idle -= new EventHandler(Application_Idle);
if (context.MainForm == null)
{
frmLogin mw = new frmLogin();
context.MainForm = mw;
//mw.Init();
frmSplash sp = (frmSplash)context.Tag;
sp.Close();
mw.Show();
}
}
请高手指点,只是偶尔出错,另外我用了DotNetBar控件,不是是否有什么影响。