msoflin
New member
I have an app that periodically calls CopyToScreen to grab and save a screenshot. It seems that every time I do this I create a GDI object that I can't seem to dispose. I've boiled it down to a simple form with a timer. The code for the form follows:
Option Strict On
Option Explicit On
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim screenSize As Size = My.Computer.Screen.Bounds.Size
Using bmp As New Bitmap(screenSize.Width, screenSize.Height)
Using g As Graphics = Graphics.FromImage(bmp)
g.CopyFromScreen(0, 0, 0, 0, screenSize)
End Using
End Using
End Sub
End Class
I'm watching GDI counters using Process Explorer which I downloaded from Microsoft. The GDI counter will increment up to 10,000 and stay there. I also see my Private Bytes increase.
As a side note, I tried creating a thread for this and got the same results. It seems like I'm missing something pretty basic here. Any help would be appreciated.
Option Strict On
Option Explicit On
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim screenSize As Size = My.Computer.Screen.Bounds.Size
Using bmp As New Bitmap(screenSize.Width, screenSize.Height)
Using g As Graphics = Graphics.FromImage(bmp)
g.CopyFromScreen(0, 0, 0, 0, screenSize)
End Using
End Using
End Sub
End Class
I'm watching GDI counters using Process Explorer which I downloaded from Microsoft. The GDI counter will increment up to 10,000 and stay there. I also see my Private Bytes increase.
As a side note, I tried creating a thread for this and got the same results. It seems like I'm missing something pretty basic here. Any help would be appreciated.