I would like to take screenshots at a defined interval of up to 20 ms. I don't think I can use the Timer class, as it's max resolution of ~ 15 ms could be a problem. However, my biggest problem is that taking a screenshot takes too long time:
Stopwatch myStopwatch = new Stopwatch();
myStopwatch.Start();
Bitmap printscreen = new Bitmap(1280, 720);
Graphics graphics = Graphics.FromImage(printscreen as Image);
graphics.CopyFromScreen(200, 200, 0, 0, new Size(1280, 720));
printscreen.Save(myOutputLocation + "image" + myImageCount.ToString() + ".png");
myImageCount += 1;
myStopwatch.Stop();
MessageBox.Show(myStopwatch.Elapsed.TotalMilliseconds.ToString());
// Elapsed time is anywhere between 60 - 95 ms
A high precision timer is able to deliver the precision I need, but I have read that your executed code should be faster than 1 millisecond. How can I speed up my code?