[英]WinForms too many handles
我的生產,我的申請引起了兩個不同的例外:
System.ArgumentException: Invalid Parameter.
at System.Drawing.Image.get_RawFormat()
at System.Windows.Forms.ToolStripItem.set_Image(Image value)
at Zeiss.IMT.IME.CmmUI.Tools.ToolControl.updateControls()
還有另一個例外,我想有相同的原因:
System.ComponentModel.Win32Exception: The operation completed successfully
at System.Drawing.BufferedGraphicsContext.CreateCompatibleDIB(IntPtr hdc, IntPtr hpal, Int32 ulWidth, Int32 ulHeight, IntPtr& ppvBits)
at System.Drawing.BufferedGraphicsContext.CreateBuffer(IntPtr src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height)
at System.Drawing.BufferedGraphicsContext.AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
at System.Drawing.BufferedGraphicsContext.AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
at System.Drawing.BufferedGraphicsContext.Allocate(IntPtr targetDC, Rectangle targetRectangle)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在兩個例外情況下,Windows任務管理器都會顯示很多句柄(> 8500)。 因此達到了Windows句柄限制,應用程序無法分配更多內存/句柄。
到目前為止,我理解這個問題。
在這種情況下,我通過System.Drawing大量使用GDI繪圖。 所以我搜索了我的代碼,其中圖形句柄沒有發布 - 沒有成功。
所以問題是:
我怎樣才能找到未發布的(原生)句柄???
您可以使用內存配置文件工具。 例如: http : //www.red-gate.com/products/dotnet-development/ants-memory-profiler/
但是你處理所有Disposable對象了嗎? 刷子等......
您可以發布您的繪圖代碼,也許我們可以看到錯誤。
也許有一些刷子,...沒有處理。
檢查您的代碼,確保在不再需要時釋放所有的一次性物品。 將一次性對象打包到using語句中。
如果真的需要這么多GDI句柄,你可以增加最大值http://msdn.microsoft.com/en-us/library/windows/desktop/ms724291(v=vs.85).aspx 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.