我有屏幕检测代码:
private Image CaptureScreen()
{
Rectangle screenSize = Screen.PrimaryScreen.Bounds;
Bitmap target = new Bitmap(screenSize.Width, screenSize.Height);
using (Graphics g = Graphics.FromImage(target))
{
g.CopyFromScreen(0, 0, 0, 0, new Size(screenSize.Width, screenSize.Height));
}
return target;
}
我每隔2毫秒用Timer调用它
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.Image = CaptureScreen();
}
15秒后应用程序崩溃,因为使用了很多内存。我怎么能阻止这个?
答案 0 :(得分:4)