尝试关闭 DesktopWindowXamlSource 时引发的异常

Exception thrown when attemping to close DesktopWindowXamlSource

本文关键字:异常 DesktopWindowXamlSource      更新时间:2023-10-16

我正在为我的Win32 C++应用程序使用UWP Xaml托管API。我有以下代码:

winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager XamlManager = winrt::Windows::UI::Xaml::Hosting::
WindowsXamlManager::InitializeForCurrentThread();
winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource XamlSource;

当我完成 UWP 内容时,我正在调用

XamlSource.Close();
XamlManager.Close();

但调试器的输出窗口指示正在引发异常:windowsadvcorewinrtiwindowcorewindowdesktopdesktopwindowcontentbridge.cpp(499)Windows.UI.dll!00007FFD91CD860F: (caller: 00007FFD91CD7704) ReturnHr(1) tid(7168) 8007139F The group or resource is not in the correct state to perform the requested operation.

我做错了什么?

您是否展示了您的应用程序?

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">unaware</dpiAwareness>
</windowsSettings>
</application>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<maxversiontested Id="10.0.18362.0"/>
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
</assembly>

从我的文章。