繁体   English   中英

C# - “没有足够的存储空间来处理此命令”异常消息

[英]C# - "Not enough storage is available to process this command" exception message

这个异常是在我们正在运行的一个系统上引发的。 到目前为止,在这台机器上的过去 6 周内,此异常已发生两次。 第一次发生时,我们没有正确的日志记录来显示完整的堆栈跟踪,所以我只能看到它来自 class 的 DataDisplayRealTimeViewModel.SetSeriesVisibilty DataDisplayRealTimeViewModel.SetSeriesVisibilty()方法。 最近一次发生这种情况时,我们有正确的日志记录,并显示了下面的堆栈跟踪。

堆栈跟踪:

Unhandled exception message: Not enough storage is available to process this command
Unhandled exception stack trace:    at MS.Win32.UnsafeNativeMethods.RegisterClassEx(WNDCLASSEX_D wc_d)
   at MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)
   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()
   at Chromatogram.DataDisplay.Control.DataDisplayRealTimeViewModel.<>c__DisplayClass210_0.<SetSeriesVisiblity>b__0()
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

在网上看了之后,我偶然发现了这个帖子 这使我开始研究监视Atom Table 我在网上找到了这个工具来帮助监控原子表,这样我就可以检查条目。 让机器在周末运行后,我可以看到很多名为HwndWrapper[OurApplicationsName;;UniqueID] --RWM的条目。

下面是引发异常的代码:

ProgressBarUserControl progressBarUserControl = null;
Application.Current.Dispatcher.Invoke((Action)(() =>
{
    progressBarUserControl = new ProgressBarUserControl();
    progressBarUserControl.Owner = System.Windows.Application.Current.Windows[0];
    progressBarUserControl.ShowInTaskbar = false;
    progressBarUserControl.Title = "Detector";
    progressBarUserControl.TitleProcess = MetaData.GetLocalizeValue("DetectorSwitchingMessage");
    progressBarUserControl.PercentageDone = "5";
    progressBarUserControl.WindowStartupLocation = WindowStartupLocation.CenterOwner;
    progressBarUserControl.Show();
}));

调用Show()方法后,我们做一些其他的逻辑,然后在这个 function 的最后,我们在这个 object 上调用Close()方法。

Application.Current.Dispatcher.Invoke((Action)(() =>
{
    if (progressBarUserControl != null)
    {
        progressBarUserControl.PercentageDone = "100";
        progressBarUserControl.Close();
    }
}));

我遇到了这篇文章,这篇文章中的问题看到了与原子表类似的条目。 我不认为这是我问题的答案,因为如果我错了,请纠正我,当前代码没有创建新的调度程序 object。 它只是调用应用程序的调度程序。 旁注:此代码位于 UI 线程上,因此我认为此处可能不需要Invoke()

我运行了一些测试,上面的代码(不包括中间逻辑)在一个循环中,迭代了 1000 次,你可以看到条目被添加到原子表中。 我运行了这个测试 3 次,平均大约 60 个条目进入原子表。 我运行了其他测试,其中我注释掉了Show()Close()方法,但我没有看到任何条目添加到 atom 表中。 So it seems that this object, which inherits from the System.Windows.Window class, is creating these RWM entries and adding them to the atom table. Atom Table文档中,它指出

但是,在 session 结束之前,RegisterWindowMessage 和 RegisterClipboardFormat 添加的条目不会被删除。 如果用户原子表没有更多空间并且传入的字符串不在表中,则调用将失败。

要补充的一件事是,这些机器旨在 24/7 全天候运行。 在我的测试机器上,上面的代码每分钟都会发生一次,并且每次调用Show()方法时似乎都没有向原子表添加一个条目。

那么,为什么它会创建这么多这些条目,有没有办法解决这个问题?

编辑1:我查看了评论中的建议并尝试了各种测试,但这些似乎不是我问题的原因。 我应该注意,我正在运行一个测试,其中我注释掉了Invoke()和里面的代码,并且这些HwndWrapper[OurApplicationsName;;UniqueID] --RWM在整个 Atom 表中增加。

编辑 2:就这个问题联系了 OP,因为它看起来有点相似。 评论中的一些有用信息。 尽管如此,我的问题仍然没有完整的解决方案。

已经有一段时间了,但我想就我的问题发表评论和更新。 我发现了泄漏的原子。 我们有一个 class,它在实例化时会实例化DispatcherTimer class 的 object。 当您查看此 class 的内部结构并跟进它时,它会创建原子并将其添加到具有条目名称的原子表中HwndWrapper[OurApplicationsname;;UniqueID] 只有在 object 本身上运行Stop() function 时,此 Hwnd 才会被破坏。 大约 99% 的时间我们创建了DispatcherTimer object,我们甚至不会使用 object 本身。 一些移动修复了泄漏。 现在,在这些机器上运行这个补丁几天后,该软件不会向原子表添加任何额外的HwndWrapper[OurApplicationsname;;UniqueID]条目。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM