Win32Exeption:操作成功完成...图形

时间:2012-05-16 18:52:39

标签: c# .net graphics exception-handling win32exception

我搜索了一些解决方案,但没有一个人显示解决方案......如果有人能够解释它为什么会发生以及如何解决它(以简单的方式),我将不胜感激:)

一直发生在同一个地方......在我启动程序后的几分钟。

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

在此之前它会运行几次(比如40-80次):

  

Win32Exeption未处理:操作成功完成

2 个答案:

答案 0 :(得分:1)

在继续之前,请创建一个try和catch语句:

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");
}

答案 1 :(得分:0)

原来我必须bmpScreenShot.Dispose();gfxScreenShot.Dispose();