I built simple application to take full screenshot each 100ms of computer's screen and set the screenshots on the PictureBox :
- private void StartWork()
- {
- try
- {
-
- using (Image bitmap = new Bitmap(1916, 1074))
- {
- using (Graphics g = Graphics.FromImage(bitmap))
- {
- g.CopyFromScreen(Point.Empty, Point.Empty, new Size(1916, 1074));
- }
- pictureBox1.BackgroundImage = (Image)bitmap.Clone();
- pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
-
-
-
- pictureBox1.Invalidate();
- pictureBox1.Refresh();
- }
- }
- catch (Exception ee)
- {
-
- }
- }
calling StartWork() in every 100ms in Tick event :
- private void timer1_Tick(object sender, EventArgs e)
- {
- StartWork();
- }
it is run well and i see the screenshots appears on PictureBox one after one but after several seconds I am facing this exception :
Data = {System.Collections.ListDictionaryInternal}
HResult = -2147024809
Message = "Parameter is not valid."
Source = "System.Drawing"
StackTrace = " at System.Drawing.Graphics.GetHdc()\r\n at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)\r\n at System.Drawing.Graphics.CopyF...
TargetSite = {IntPtr GetHdc()}
I was searched in simillar problems in CSharp Corner and Stackoverflow and try to change a lot of things but really i becommed tired.
please developers how solve this problem .
Thanks in Advance .