下面的代码会因为异常而崩溃:
MyWindow wnd = new MyWindow();
wnd.Show(); //here an exception occurs
异常相当奇怪,但据我理解这是 .net 中的一个 bug。
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()
我的窗口对象是一个带有一些矢量图形的窗口,但不是太多。此外,当已经打开和关闭了10-20个MyWindow对象时,它会出现。
解决方案:问题原因是GDI对象泄漏。这些对象在我低级代码中创建时出现了错误。因此,该问题与MyWindow对象无关。
App.xaml.cs
中的Startup()
方法并在其中使用window.Show()
。当我尝试使用BluetoothWin32Authentication的处理程序时,这可能会导致问题吗? - Mehrad