【发布时间】:2009-07-30 22:32:37
【问题描述】:
我在长时间运行 Windows 窗体应用程序时有时会遇到此异常:
System.ComponentModel.Win32Exception: The operation completed successfully
at System.Drawing.BufferedGraphicsContext.CreateCompatibleDIB(IntPtr hdc, IntPtr hpal, Int32 ulWidth, Int32 ulHeight, IntPtr& ppvBits)
at System.Drawing.BufferedGraphicsContext.CreateBuffer(IntPtr src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height)
at System.Drawing.BufferedGraphicsContext.AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
at System.Drawing.BufferedGraphicsContext.AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
at System.Drawing.BufferedGraphicsContext.Allocate(IntPtr targetDC, Rectangle targetRectangle)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
这可能是什么原因?
【问题讨论】:
-
我在 google 上找到了 1400 次关于此的点击,但没有一个看起来像真正的解释。
-
我看到这条错误消息是因为一个完全不同的异常 (
Microsoft.ActiveDirectory.Management.Commands.GetADPrincipalGroupMembership)。每当错误发生在 Windows API(即非托管代码)中时,就会发生这种情况,并且在检索错误消息以将其添加到(托管)异常之前被覆盖,因为后者正在构建中。引用deleted Wikipedia page, ... -
"如果程序调用 Win32 函数失败,程序可以调用 GetLastError 来检索描述初始函数调用失败原因的错误代码;但是 GetLastError 仅返回与最后一个系统函数相关的错误代码调用,因此如果程序进行了另一个成功的函数调用(紧接在 GetLastError 之前),则返回的错误代码将为零,表示“操作成功完成”,通常会通过消息框显示给用户。”跨度>
标签: c# .net winforms win32exception