I am using a C# program to save about 10 screen captures of size 660x330 per second.
This C# program is used as a .dll script for the game GTA V.
Bitmap catchBmp = new Bitmap(300, 660, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
Graphics g = Graphics.FromImage(catchBmp);
g.CopyFromScreen(new Point(Screen.AllScreens[0].Bounds.Width / 3 + 170, Screen.AllScreens[0].Bounds.Height / 6 + 60), new Point(0, 0), new Size(300, 660));
string tmp = Path.Combine(path, modNum.ToString(), location);
if (!Directory.Exists(tmp))
{
Directory.CreateDirectory(tmp);
}
string tmp_filename = tmp + "\\" + location + "_" + weather + "_" + time + "_" + anim + "_" + view_angle + "_" + modNum + "_" + picNum.ToString() + ".jpg";
catchBmp.Save(tmp_filename);
UI.ShowSubtitle(tmp_filename);
Wait(100);
catchBmp.Dispose();
g.Dispose();
The code above is ran in a loop, running about 10 times per second.
After the script runs for about 6 hours or so, my hard drive seems to reach maximum usage and the script crashes.
Is there a way to prevent this? I would like to run this script for days at a time.
Would using a thread to save the images be helpful? Or implementing a queue while saving it to disk?