leora
leora

Reputation: 196459

Window handle debugging in Winforms

I have a user that keeps getting this error. Is there a tool that does window handle counting that i can use to figure out why he keeps getting this error.

System.ComponentModel.Win32Exception: Error creating window handle. at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp) at System.Windows.Forms.Control.CreateHandle() at System.Windows.Forms.Form.CreateHandle() at System.Windows.Forms.Control.get_Handle() at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)

Upvotes: 1

Views: 2742

Answers (3)

Joe Clancy
Joe Clancy

Reputation: 1437

If the Form you are creating overrides WndProc(), be careful to ensure that it always calls base.WndProc() during the window creation process.

I inadvertently omitted a call to base.WndProc() in my override, and got your stack trace.

Upvotes: 2

Hans Passant
Hans Passant

Reputation: 941307

The best counter I know is Taskmgr.exe. View + Select Columns and check "User objects", "Handle count" and "GDI Objects".

The generic diagnostic is that you're leaking handles and consumed 10,000 of them. Beware of a handle leak bug in .NET 2.0 SP1 and .NET 3.5's Graphics.CopyFromScreen(), fixed in 3.5 SP1.

Upvotes: 1

Robert Vuković
Robert Vuković

Reputation: 4688

Maybe this could help:

Unhandled exception Win32Exception,Error creating window handle

CLR Debugger (DbgCLR.exe)

on mine machine debugger is located at:

"c:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\GuiDebug\DbgCLR.exe" 

Upvotes: 1

Related Questions