The following code crashes with an exception :
MyWindow wnd = new MyWindow();
wnd.Show(); //here an exception occurs
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 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.
Solution: The reason was a leak of GDI objects.They were creating in my low level code containing a mistake. So, the problem had no concern to MyWindow object.