Pergunta

I've got a program which is doing some geometrical analysis in a background thread.

Usually this worked quite well, but surprisingly now I get an exception when trying to create a PathGeometry on my development computer:

So on the simple code:

PathGeometry geometry = new PathGeometry();

I get an System.TypeInitializationException {"Der Typeninitialisierer für \"System.Windows.Media.PathGeometry\" hat eine Ausnahme verursacht."}
Stack Trace is:

bei System.Windows.Media.PathGeometry..ctor()
bei Bsoft.ilka.AlkisLeser.AlkisDatei.GetPosition(XElement xe) in AlkisDatei.cs:Zeile 267.

This exception contains the InnerException System.ComponentModel.Win32Exception {"Ungültiges Fensterhandle"} Stack trace of the InnerException is:

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()

Strange thing: The executable does work on some other computer.

What is the problem? Why does the PathGeometry constructor try to access some window handle? How do I resolve this?

I'm using .NET framework 4.0 and the code throws on both VS2010 and VS2012.

Foi útil?

Solução

You'll get this stack trace when the native CreateWindowEx() api function call fails. There are very few reasons for it to fail, but one. It is likely your program suffers from a handle leak, consuming 10,000 window handles. At which point Windows refuses to let you create more.

Diagnose with Taskmgr.exe, Processes tab. View + Select columns, tick USER Objects. Also tick Handles and GDI Objects, just in case. Observe the displayed values for your process. A steadily climbing value for USER Objects spells doom. Finding the cause of the leak can be a bit difficult. Certainly consider a memory profiler. Arbitrarily comment out chunks of code. If you don't see the leak in Taskmgr.exe then there's some kind of other process messing with yours. Arbitrarily kill them one by one to find the troublemaker.

Last but not least, seeing a worker thread creating a window is a recipe for trouble. I don't know enough about PathGeometry but it certainly doesn't look like the kind of class that could function correctly on a worker.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top