I am attempting to invoke a method as many times as possible given its within 1 second, so I decided to use a timer to help perform this, but when the timer runs the tick event handler (after 1 seconds) the method is still invoked - I have started it of as follows:
public partial class Form1 : Form
{
public static Timer prntScreenTimer = new Timer();
public Form1()
{
InitializeComponent();
startCapture();
}
private static void startCapture()
{
prntScreenTimer.Tick += new EventHandler(prntScreenTimer_Tick);
prntScreenTimer.Start();
prntScreenTimer.Interval = 1000;
while (prntScreenTimer.Enabled)
{
captureScreen();
}
}
private static void prntScreenTimer_Tick(object sender, EventArgs e)
{
prntScreenTimer.Stop();
}
private static void captureScreen()
{
int ScreenWidth = Screen.PrimaryScreen.Bounds.Width;
int ScreenHeight = Screen.PrimaryScreen.Bounds.Height;
Graphics g;
Bitmap b = new Bitmap(ScreenWidth, ScreenHeight);
g = Graphics.FromImage(b);
g.CopyFromScreen(Point.Empty, Point.Empty, Screen.PrimaryScreen.Bounds.Size);
// Draw bitmap to screen
// pictureBox1.Image = b;
// Output bitmap to file
Random random = new Random();
int randomNumber = random.Next(0, 10000);
b.Save("printScrn-" + randomNumber, System.Drawing.Imaging.ImageFormat.Bmp);
}
}
}