I am creating an application that runs on a timer, and each tick I want to take a screenshot and save it to the disk. This should be running in the background, so I want it to take up as little CPU time as possible. However, when I ran a performance analysis, I found that around 40% of the time was spent in Bitmap.Save
and my CPU usage is up to around 10%-15% on average (it's an old computer)
So my question is, is there any way to throttle the image saving process so that Bitmap.Save
won't use so much processor time?
I have tried setting Thread.CurrentThread.Priority = ThreadPriority.Lowest;
but that did not change much, and neither did using a thread pool.
Here's what I'm doing:
public static void SaveScreenshot(string path)
{
Bitmap bmp = TakeScreenshot();
Directory.CreateDirectory(Path.GetDirectoryName(path));
bmp.Save(path);
bmp.Dispose();
}