Keep getting "Error creating window handle" System.ComponentModel.Win32Exception for unknown reason

H

Hasani

I made a custom control and I get an error when I add 130+ items to the
form's Control.
If I add this custom control once, it works. If I take that same form, and
perform a deep copy 200 times and add it to the control, it works. When I
invoke Show(), it begins to show/draw each control in the form that I added,
but later it throws an exception. Calling Show() a second time will show
what forms were loaded the 1st time I called Show().

here's a stack trace

StackTrace " at
System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.TextBoxBase.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.ScrollableControl.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.ScrollableControl.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Form.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32
nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Control.Show()
at MyFormTester.Form1.GetItems(Object sender, EventArgs e) in c:\\documents
and settings\\hasani\\my documents\\visual studio
projects\\MyFormTester\\form1.cs:line 365" string


here's the method

private void GetItems(object sender, System.EventArgs e)

{

statusBarForm.Text = "Retrieving items from search engine."; //line 354

Hide();//line 355

InitializeStatusBar();//line 356

lastClicked = sender;//line 357

SuspendLayout();//line 358

statusBarForm.Run(this);//line 359

while(!statusBarForm.Completed)//line 360

Application.DoEvents();//line 361

ResumeLayout(true);//line 362

try

{

Show();//line 365

}

catch(Win32Exception err)

{

MessageBox.Show(err.Message + "\r\n" + err.StackTrace);//line 369

Show();

}

}


Line 359 runs a method in a background thread that adds item to the form's
Control using the method Invoke. I successfully reach line 362, when I
execute line 365, I see the form display again and windows redraws each
control on the form. It takes a few seconds and then I get the exception. I
added the Show method later (line 370), and it succesfully displayed the
form without redrawing/refreshing and without throwing an exception. I
didn't count how many controls were on the form (it added 150 controls to
the Form, it , but The last control visible is drawn/displayed incomplete.



So umm, anyone else encounter this problem, and what do I do fix it.
 
H

Hasani

Ok, I found out what the problem was.
I was displaying too many Controls on the form, thus eating up resources.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top