C# Win32 Exeption:操作已成功完成。。。绘图

C# Win32 Exeption:操作已成功完成。。。绘图,c#,.net,graphics,exception-handling,win32exception,C#,.net,Graphics,Exception Handling,Win32exception,我搜索了一些解决方案,但没有一个人显示解决方案。。。如果有人能解释它发生的原因以及如何解决它(以一种简单的方式),我将不胜感激: 总是发生在同一个地方。。。在我开始节目几分钟后 private static Bitmap bmpScreenShot; private static Graphics gfxScreenShot; ... ... bmpScreenShot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.Pri

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

总是发生在同一个地方。。。在我开始节目几分钟后

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
私有静态位图bmpScreenShot;
私人静态图形gfxScreenShot;
...
...
bmpScreenShot=新位图(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);// 在继续之前,请创建一个try-and-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");
}

结果我不得不做
bmpScreenShot.Dispose()
gfxScreenShot.Dispose()

它又运行了一次,只出现在bmpScreenShot=行中说(ArgumentException未经处理|-|参数无效)。。。有什么解决办法吗?。。。顺便说一句(如果我在黄色三角形中出现错误或者我可以跳过它们吗?),当我添加一个例外时,每次调用此代码时都会发生,导致代码bmpScreenShot=新位图(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height,PixelFormat.Format32bppArgb);不被处决:S