Closed JasonBurton2 closed 10 years ago
If I Dispose() the Screenshot object, my problem is corrected, like:
private void button1_Click(object sender, EventArgs e)
{
new Thread(testCapture).Start();
}
public void testCapture()
{
for (int i = 0; i < 200; i++)
{
Screenshot s = _captureProcess.CaptureInterface.GetScreenshot();
Bitmap b = s.CapturedBitmap.ToBitmap();
s.Dispose();
// didn't have to, or want to, Dispose() the Bitmap since that is what I need
}
}
Yes, these screenshot objects are instantiated within the target application, so it is quite important that they are disposed of correctly. There was a critical fix a while ago to ensure that the MarshalByRef objects' lifetime service would release the object when disposed.
I would suggest always wrapping in a using block like so:
using (Screenshot s = _captureProcess.CaptureInterface.GetScreenshot())
{
... do stuff with s
}
My application captures a screenshot of a 32-bit DirectX application (BlueStacks) whenever it needs it. It works fine, but after about 150 calls, it crashes BlueStacks (not the program that is performing the capture). So I tested it with the "Load Test" button on the TestScreenshot application. It does not crash BlueStacks. However, if I execute the code below from a button click in the TestScreenshot application, it does crash BlueStacks. Is there something I am doing wrong with this? Here is the code: