How to resolve the winforms error “A generic error occurred in GDI+. ”?

倖福魔咒の 提交于 2019-12-05 11:57:55

Your code is probably leaking GDI resources badly. Have a look with Taskmgr.exe, Processes tab. View + Select Columns and tick Handles, USER objects and GDI objects. Run your program and observe the displayed values for your process. A constantly climbing value for GDI objects spells trouble, the show is over when it reaches 10,000.

Exactly what might cause the leak is not quite that easy to diagnose. Although you can single-step your code in the debugger and keep an eye on the taskmgr number. The classic mistake is creating pens and brushes in a Paint event handler and not disposing them. Without the garbage collector running often enough to clean up. Use the using statement to fix.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!