我有一个在后台线程中进行几何分析的程序。
通常情况下,这种方法运行得很好,但令人惊讶的是,现在我在开发计算机上创建PathGeometry时出现异常:
因此,在简单的代码中:
PathGeometry geometry = new PathGeometry();我得到了一个System.TypeInitializationException {"Der Typeninitialisierer für \"System.Windows.Media.PathGeometry\“hat eine Ausnahme verursacht”}
堆栈跟踪是:
bei System.Windows.Media.PathGeometry..ctor()
bei Bsoft.ilka.AlkisLeser.AlkisDatei.GetPosition(XElement xe) in AlkisDatei.cs:Zeile 267.此异常包含InnerException的InnerException System.ComponentModel.Win32Exception {"Ungültiges Fensterhandle"}堆栈跟踪:
bei MS.Win32.UnsafeNativeMethods.GetWindowLongWndProc(HandleRef hWnd)
bei MS.Win32.HwndSubclass.UnhookWindowProc(Boolean force)
bei MS.Win32.HwndSubclass.Dispose()
bei MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)
bei System.Windows.Threading.Dispatcher..ctor()
bei System.Windows.Threading.Dispatcher.get_CurrentDispatcher()
bei System.Windows.DependencyObject..ctor()
bei System.Windows.Media.PathFigureCollection.get_Empty()
bei System.Windows.Media.PathGeometry..cctor()奇怪的是:这个可执行文件可以在其他计算机上运行。
有什么问题吗?为什么PathGeometry构造函数试图访问一些窗口句柄?我该如何解决这个问题?
我使用的是.NET Framework4.0,代码在VS2010和VS2012上都是错误的。
发布于 2012-09-24 21:26:35
当本机CreateWindowEx() api函数调用失败时,您将获得此堆栈跟踪。它失败的原因很少,但只有一个。您的程序很可能存在句柄泄漏,消耗了10,000个窗口句柄。在这一点上,Windows拒绝让您创建更多内容。
使用Taskmgr.exe诊断,进程选项卡。查看+选择列,勾选用户对象。还有tick Handles和GDI对象,以防万一。观察您的进程的显示值。用户对象的值稳步攀升意味着厄运。找出泄漏的原因可能有点困难。当然可以考虑内存分析器。任意注释掉代码块。如果你没有发现Taskmgr.exe中的漏洞,那么一定有其他进程在扰乱你的进程。任意杀掉他们一个一个来找出麻烦制造者。
最后但并非最不重要的一点是,看到一个工作线程创建一个窗口会带来麻烦。我对PathGeometry了解不多,但它看起来肯定不像是那种可以在worker上正常工作的类。
https://stackoverflow.com/questions/12565429
复制相似问题