Win32Exception:操作成功完成 [英] Win32Exception: Operation completed successfully

查看:424
本文介绍了Win32Exception:操作成功完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码崩溃,但异常:

The following code crashes with an exception :

MyWindow wnd = new MyWindow();
wnd.Show(); //here an exception occurs

异常相当奇怪,但据我所知它是.net中的错误

Exception is rather strange but as I understand its a bug in .net

System.ComponentModel.Win32Exception (0x80004005): The operation completed successfully
   at MS.Win32.UnsafeNativeMethods.GetDC(HandleRef hWnd)
   at System.Windows.Interop.HwndTarget..ctor(IntPtr hwnd)
   at System.Windows.Interop.HwndSource.Initialize(HwndSourceParameters parameters)
   at System.Windows.Interop.HwndSource..ctor(HwndSourceParameters parameters)
   at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
   at System.Windows.Window.CreateSourceWindowDuringShow()
   at System.Windows.Window.SafeCreateWindowDuringShow()
   at System.Windows.Window.ShowHelper(Object booleanBox)
   at System.Windows.Window.Show()

MyWindow对象是一个内部带有一些矢量图形的窗口,但不是太多。同样,当已经打开和关闭10-20个MyWindow对象时,就会发生这种情况。

MyWindow object is a window with some vector graphics inside, but not too much. Also, it happens when 10-20 MyWindow objects have been opened and closed already.

解决方案:原因是GDI对象泄漏。它们是在我的低级代码中创建的,其中包含错误。因此,问题与MyWindow对象无关。

推荐答案

它不会在winapi错误代码上轰炸,实际错误代码是E_FAIL,一个COM错误代码。这对诊断任何事情都无济于事,它的含义不只是做不到,不知道为什么。 GetDC()如何产生该错误代码很难猜测,我怀疑它与winapi函数挂钩是环境问题。也许类似于远程桌面或屏幕录像机。尝试在另一台机器上运行它。

It doesn't bomb on a winapi error code, the actual error code is E_FAIL, a COM error code. Which is very unhelpful to diagnose anything, it doesn't mean anything more than "couldn't do it, no idea why". How GetDC() can produce that error code is very hard to guess, I suspect it is environmental with something hooking the winapi function. Perhaps something similar to remote desktop or a screen recorder. Do try running this on another machine.

GetDC()失败的正常原因是句柄泄漏。 Windows已经消耗了10,000个进程时,将停止为该进程提供更多的句柄。您可以使用TaskMgr.exe的进程选项卡进行诊断。查看+选择列,然后勾选句柄,用户对象和GDI对象。首先检查进程列表,并确认您没有消耗大量进程的进程。会话中所有进程的GDI对象总数受会话池大小限制。接下来运行您的程序,并注意您的过程的值。

The "normal" reason for GetDC() failure is a handle leak. Windows stops giving a process more handles when it has consumed 10,000 of them already. Something you can diagnose with TaskMgr.exe, Processes tab. View + Select Columns and tick Handles, USER Objects and GDI Objects. First check the list of processes and verify that you don't have a process that consumes a lot of them. The total number of GDI Objects for all processes in a session is limited by the session pool size. Next run your program and keep an eye on the values for your process.

这篇关于Win32Exception:操作成功完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆