开发者

strange exception which appears once in a while, could not reproduce the steps on WinForms UI

Exception type: System.ComponentModel.Win32Exception
Exception message: Error creating window handle.

I could not reproduce it in development environ, although from time to time it appears at the end user. I know this may be a little too general and vague, but if you encountered such an exception what were the potential开发者_运维百科 causes?


Take a look at "Error Creating Window Handle" and http://www.aboutmydot.net/index.php/unhandled-exception-win32exceptionerror-creating-window-handle


There are a couple of possibilities for this exception. But if it is intermittent then there's really only one. Your code is leaking window handles. A program can allocate up to 10,000 of them before Windows pulls the plug and refuses to allow it to create any more.

Hard to repro because leaks like this take a while to build up to the quota. But easily observed from Taskmgr.exe. Click the Processes tab, View + Select columns and tick "USER objects". Observe this number while you run your program. It will go up by one every time your app creates a new form or control. And should go down when you close a form.

Unfortunately it is fairly easy to make a mistake that causes such a leak. It happens when you remove a control from a form without calling its Dispose() method. Or calling Controls.Clear() without disposing the controls first. Controls that are removed like that are temporarily hosted on the "parking window". With the intent that it will survive long enough to allow you to move them to another container. If that doesn't happen then the window handle for the control is permanently leaked.


From what I can see, this is an exception when your error handling dialog is trying to be displayed.


Possibly, the application has a lot of forms being opened by user but not necessarily closed and disposed properly. Things like these are pretty hard to reproduce because developers and QA folks usually never use the app like the end user.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜