You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法捕获WPF窗口Show()抛出的Win32Exception(配额不足)问题求助

问题:无法捕获WPF窗口Show()引发的Win32Exception

我有一个桌面应用,其中包含第三方创建的小型XAML窗口。调用该窗口时会触发System.ComponentModel.Win32Exception导致崩溃,异常信息为**"Not enough quota is available to process this command"**,且仅在打开多个文件后才会触发。

触发异常的代码

触发操作是简单的window.Show()调用,我尝试了多种捕获方式均失败,代码如下:

try
{
    var window = new System.Windows.Window
    {
        ResizeMode = ResizeMode.NoResize,
        Content = new EdgeBarPageView(),
        WindowStyle = WindowStyle.None
    };
    window.Show();

    return new WindowInteropHelper(window).Handle;
}
//catch (Exception e)
//{
//    MessageBox.Show(e.Message + "\n" + e.StackTrace, "GetEdgeBarView - Running GC and trying again.");
//}
catch (Win32Exception ex) when (ex.InnerException is Win32Exception)            //catch(System.ComponentModel.Win32Exception e)
{
    MessageBox.Show(ex.Message + "\n" + ex.StackTrace, "GetEdgeBarView - Running GC and trying again.");
}

尝试过的捕获方案(均无效)

  • 最初添加Exception捕获分支,无法捕获异常
  • 注释掉Exception分支后单独捕获System.ComponentModel.Win32Exception,依然失败
  • 参考代码添加带when条件的捕获分支,还是无法拦截异常

环境与相关代码说明

  • 异常发生时GDI对象计数低,系统内存充足(32GB物理内存+100GB交换空间,已提交内存不足32GB),但应用本身及处理的文件较大
  • 第三方XAML控件代码简单:
public partial class EdgeBarPageView : UserControl
{
    public EdgeBarPageView()
    {
        InitializeComponent();
    }
}

完整调用栈

PresentationCore.dll!System.Windows.Interop.HwndTarget.UpdateWindowSettings Unknown
PresentationCore.dll!System.Windows.Interop.HwndTarget.UpdateWindowPos  Unknown
PresentationCore.dll!System.Windows.Interop.HwndTarget.HandleMessage    Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.HwndTargetFilterMessage  Unknown
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc    Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation   Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall  Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen  Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl    Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc   Unknown
[Native to Managed Transition]  
user32.dll!UserCallWinProcCheckWow  Unknown
user32.dll!DispatchClientMessage    Unknown
user32.dll!__fnINOUTLPPOINT5    Unknown
ntdll.dll!KiUserCallbackDispatcherContinue  Unknown
win32u.dll!NtUserSetWindowPos   Unknown
WindowsBase.ni.dll!00007ff971c778c1 Unknown
[Managed to Native Transition]  
PresentationFramework.dll!System.Windows.Window.Flush   Unknown
PresentationFramework.dll!System.Windows.Window.HwndStyleManager.System.IDisposable.Dispose Unknown
PresentationFramework.dll!System.Windows.Window.CreateSourceWindow  Unknown
PresentationFramework.dll!System.Windows.Window.ShowHelper  Unknown

Isap.Prototypes.UGSCallSampleNETAddin.dll!Isap.Prototypes.UGSCallSampleNETAddin.EdgeBarService.AddPage Line 128 C#
Isap.Prototypes.UGSCallSampleNETAddin.dll!Isap.Prototypes.UGSCallSampleNETAddin.Addin.AddPage Line 216 C#
[Native to Managed Transition]

jengined.dll!CProxyISEAddInEdgeBarEventsEx::Fire_AddPage Line 1038 C++
jengined.dll!CAddIn::FireAddPage Line 4605 C++
jengined.dll!JApplication::FireEdgeBarEvent Line 1357 C++
jengined.dll!JApplication::FireActiveDocumentChange Line 248 C++
jengined.dll!JTransitionDocs Line 7334 C++
jengined.dll!JWinLayer::OnSetFocus Line 5396 C++
jengined.dll!JWinLayer::WindowProc Line 3892 C++
jengined.dll!JWinLayer::WinLayerWindowProc Line 3812 C++
user32.dll!UserCallWinProcCheckWow Unknown
user32.dll!DispatchClientMessage Unknown
user32.dll!__fnDWORD Unknown
ntdll.dll!KiUserCallbackDispatcherContinue Unknown
win32u.dll!NtUserSetFocus Unknown
jengined.dll!JApplication::ViewFrameWindowProc Line 414 C++
user32.dll!UserCallWinProcCheckWow Unknown
user32.dll!DispatchClientMessage Unknown
user32.dll!__fnDWORD Unknown
ntdll.dll!KiUserCallbackDispatcherContinue Unknown
win32u.dll!NtUserSetFocus Unknown
jengined.dll!JWinLayer::SetActive Line 6982 C++
jengined.dll!JWinLayer::IJWindowImp::put_Visible Line 3160 C++
jengined.dll!JDocWindows::ShowAllWindows Line 1193 C++
jengined.dll!JShowAllWindows Line 805 C++
jengined.dll!JDocument::Load Line 971 C++
jengined.dll!JDocument::IJPersistStorageImp::Load Line 1276 C++
jengined.dll!JDocuments::IJDocumentsImp::OpenEx Line 4527 C++
jengined.dll!OpenFile Line 17862 C++
jengined.dll!OnOpenMRUEx Line 11578 C++
jengined.dll!JBuiltInCommand::WakeUp Line 195 C++
jengined.dll!JBuiltInCommand::IJCommandImp::WakeUp Line 129 C++
jengined.dll!JSTACKENTRY::WakeUp<void const *> Line 385 C++
jengined.dll!JApplication::StartCommand<void const *> Line 2387 C++
jengined.dll!JExecuteBuiltInCommand Line 325 C++
jengined.dll!JBuiltInCommandTable::Execute Line 25321 C++
jengined.dll!StartAndExecuteCommand Line 6638 C++
jengined.dll!CommandHandler Line 6910 C++
jengined.dll!JApplication::WindowProc Line 10037 C++
jengined.dll!JApplication::EngineFrameWindowProc Line 8463 C++
user32.dll!UserCallWinProcCheckWow Unknown
user32.dll!CallWindowProcW Unknown
Microsoft.VisualStudio.Debugger.Runtime.Impl.dll!DetouredCallWindowProcW Unknown
mfc140ud.dll!_AfxActivationWndProc Line 478 C++
user32.dll!UserCallWinProcCheckWow Unknown
user32.dll!CallWindowProcW Unknown
Microsoft.VisualStudio.Debugger.Runtime.Impl.dll!DetouredCallWindowProcW Unknown
jengined.dll!JFrameWnd::OnCommand Line 8088 C++
mfc140ud.dll!CWnd::OnWndMsg Line 2113 C++
ToolkitPro2010vc160x64UD.dll!CXTPCommandBarsSiteBase::OnWndMsg Line 208 C++
mfc140ud.dll!CWnd::WindowProc Line 2099 C++
jengined.dll!JFrameWnd::WindowProc Line 15152 C++
mfc140ud.dll!AfxCallWndProc Line 265 C++
mfc140ud.dll!AfxWndProc Line 418 C++
mfc140ud.dll!AfxWndProcBase Line 299 C++
user32.dll!UserCallWinProcCheckWow Unknown
user32.dll!CallWindowProcW Unknown
Microsoft.VisualStudio.Debugger.Runtime.Impl.dll!DetouredCallWindowProcW Unknown
ToolkitPro2010vc160x64UD.dll!CXTPHookManager::HookWndProc Line 449 C++
user32.dll!UserCallWinProcCheckWow Unknown
user32.dll!DispatchMessageWorker Unknown
jengined.dll!ProcessEventLoopCPP Line 5574 C++
jengined.dll!JProcessEventLoop Line 5699 C++
jengined.dll!JMainEngine::Run Line 2402 C++
jengined.dll!JWinMain Line 300 C++
SEStartupD.dll!JStartupSolidEdgeCommon Line 488 C++
EdgeD.exe!Run_SolidEdge Line 211 C++
EdgeD.exe!CSolidEdgeWinApp::Run Line 45 C++
mfc140ud.dll!AfxWinMain Line 47 C++
EdgeD.exe!wWinMain Line 26 C++
EdgeD.exe!invoke_main Line 123 C++
EdgeD.exe!__scrt_common_main_seh Line 288 C++
EdgeD.exe!__scrt_common_main Line 331 C++
EdgeD.exe!wWinMainCRTStartup Line 17 C++
kernel32.dll!BaseThreadInitThunk Unknown
ntdll.dll!RtlUserThreadStart Unknown

核心需求

能够成功捕获该Win32Exception,避免应用崩溃。


内容的提问来源于stack exchange,提问作者RDH

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 15:57:02