You can Invoke
methods in your main thread where you can access the GUI from the Tick
Event.
In your Tick event:
this.Invoke(new MethodInvoker(delegate { this.Proceed(); }), null);
Then you can put what you want to do in the Proceed()
method.
private void Proceed()
{
string s;
s = textBox3.Text+ "\\scr_(" + pict_no + ").Jpeg";
// Set the bitmap object to the size of the screen
bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
// Create a graphics object from the bitmap
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Take the screenshot from the upper left corner to the right bottom corner
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
// Save the screenshot to the specified path that the user has chosen
bmpScreenshot.Save(s, ImageFormat.Jpeg);
pict_no++;
}