0

Ive searched some fo a solution but not a single person shows a solution... I would appreciate if someone could explain why it occurs and how to solve it (in a simple way) :)

Occurs in same place all the time... a couple of minutes after i start the program.

private static Bitmap bmpScreenShot;
private static Graphics gfxScreenShot;
...
...

bmpScreenShot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
    Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
gfxScreenShot = Graphics.FromImage(bmpScreenShot);
gfxScreenShot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
    Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, 
    CopyPixelOperation.SourceCopy); // <-- Occurs here a while after ive started the application

It runs a couple of times (say 40-80 times) before this happens:

Win32Exeption was unhandled: The operation completed successfully

abatishchev
  • 98,240
  • 88
  • 296
  • 433
user1344948
  • 141
  • 1
  • 3
  • 11

2 Answers2

1

Before you go any further, create a try and catch statement:

try
{
    //Your code goes here
}
catch (Win32Exception e)
{
    //Handle the exception here, or use one of the following to find out what the issue is:
    Console.WriteLine(e.Message);
    MessageBox.Show(e.Message, "Exception");
}
abatishchev
  • 98,240
  • 88
  • 296
  • 433
phxvyper
  • 364
  • 1
  • 4
  • 13
  • it ran one more time and only came to the bmpScreenShot = line saying (ArgumentExeption was unhandled |-| Parameter is not valid.)... any solution for this?... btw (does it matter if i get errors with the yellow triangle or can i just skip them?) – user1344948 May 16 '12 at 19:11
  • and when i add an exeption for that it happens everytime this code is called causing the code bmpScreenShot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb); to not beeing executed :S – user1344948 May 16 '12 at 19:18
0

Turns out i had to do bmpScreenShot.Dispose(); and gfxScreenShot.Dispose();

Botz3000
  • 39,020
  • 8
  • 103
  • 127
user1344948
  • 141
  • 1
  • 3
  • 11