我在這個智慧的結尾。我有一個返回圖標的函數。我的問題是,當應用程序正在運行,正在使用的功能,我可以看我的應用程序內存使用攀升。幾分鐘後,我會得到一個「在GDI +中發生的通用錯誤」,這會導致我的應用程序崩潰。 我已經通過論壇,並找到了建議,但我沒有試過似乎解決了這個問題。在函數的末尾添加.dispose()會延長髮生這種情況的時間長度,但不會使其停止。 這裏是一個有我的問題代碼:創建圖標時的通用gdi +錯誤
Private Function drawIcon(ByVal frameColor As Color, ByVal numColor As Color, ByVal capColor As Color, ByVal scrColor As Color)
Dim ti As Icon
Dim bmp As New Bitmap(16, 16)
Dim bmpgraphics As Graphics = Graphics.FromImage(bmp)
Using bmpgraphics
Dim framePen As New Pen(frameColor)
Dim numBrush As New SolidBrush(numColor)
Dim capBrush As New SolidBrush(capColor)
Dim scrBrush As New SolidBrush(scrColor)
Dim strip As Integer = 64/3
'outside
Dim numFrame As Rectangle = New Rectangle(0, 0, strip, 16 - 1)
Dim capFrame As Rectangle = New Rectangle(strip, 0, strip, 16 - 1)
Dim scrFrame As Rectangle = New Rectangle(strip * 2, 0, strip, 16 - 1)
' inside
Dim numInside As Drawing.Rectangle = New Rectangle(1, 1, strip - 1, 16 - 2)
Dim capInside As Drawing.Rectangle = New Rectangle(strip + 1, 1, strip - 1, 16 - 2)
Dim scrInside As Drawing.Rectangle = New Rectangle(strip * 2 + 1, 1, strip - 1, 16 - 2)
' do the drawing
With bmpgraphics
.DrawRectangle(framePen, numFrame)
.DrawRectangle(framePen, capFrame)
.DrawRectangle(framePen, scrFrame)
.FillRectangle(numBrush, numInside)
.FillRectangle(capBrush, capInside)
.FillRectangle(scrBrush, scrInside)
End With
'Dim tmpBmp As New Bitmap(bmp)
'ti = Drawing.Icon.FromHandle(tmpBmp.GetHicon)
'tmpBmp.Dispose()
ti = Drawing.Icon.FromHandle(bmp.GetHicon)
End Using
bmp.Dispose()
bmpgraphics.Dispose()
Return ti
End Function
問題的不一部分,但打開選項嚴格。那些pend和畫筆是需要處理的資源(或''使用'd),Icon返回也是一種資源。當用戶代碼完成後,它也需要處理。 – Plutonix
今天在網站上有一個類似的錯誤,它有圖表 - 它已經運行了幾個月,從來沒有出現過問題。做了一個iisreset,它再次工作。還不確定,如果這只是IIS的暫時性打嗝,或者我需要解決某些問題,但是我認爲如果它有幫助,我會提及它。 –
謝謝你們。我想我現在已經舔了它。我偶然發現了另一個網站上的修復程序。 – 123Andrew321