I am making a c# console application that takes a screenshot every 20-40 seconds.
I've tried looking everywhere, but all other examples don't use the console
This is the code I have made so far:
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Threading;
using System.Windows.Forms;
namespace FizzBuzz
{
class MainClass
{
public static void ScreenShot()
{
Random rnd = new Random();
int sleepTime = rnd.Next(20, 40);
int num = 0;
while (num == 0)
{
Rectangle bounds = Screen.GetBounds(Point.Empty);
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
}
bitmap.Save("screenshots.png", ImageFormat.Png);
}
Thread.Sleep(sleepTime*100);
}
}
public static void Main(string[] args)
{
ScreenShot();
}
}
}
However, when I run the code I get a long error message on the console like this:
