c# – Win32Exception没有足够的存储可用于处理此命令

前端之家收集整理的这篇文章主要介绍了c# – Win32Exception没有足够的存储可用于处理此命令前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
通过我的 MaxTo自动化崩溃收集我得到以下崩溃报告:
V8.12.0.0 - System.ComponentModel.Win32Exception - :Void UpdateLayered():0
Version: MaxTo8.12.0.0
Exception: System.ComponentModel.Win32Exception
Error message: Not enough storage is available to process this command
Stack trace: 
  at System.Windows.Forms.Form.UpdateLayered()
  at System.Windows.Forms.Form.OnHandleCreated(EventArgs e)
  at System.Windows.Forms.Control.WmCreate(Message& m)
  at System.Windows.Forms.Control.WndProc(Message& m)
  at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
  at System.Windows.Forms.ContainerControl.WndProc(Message& m)
  at System.Windows.Forms.Form.WmCreate(Message& m)
  at System.Windows.Forms.Form.WndProc(Message& m)
  at MaxTo.MainForm.WndProc(Message& m)
  at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
  at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
  at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)

另一个堆栈跟踪:

Version: MaxTo2009.9.0.0
Exception: System.ComponentModel.Win32Exception
Error message: Not enough storage is available to process this command
Stack trace: 
  at System.Windows.Forms.Form.UpdateLayered()
  at System.Windows.Forms.Form.OnHandleCreated(EventArgs e)
  at System.Windows.Forms.Control.WmCreate(Message& m)
  at System.Windows.Forms.Control.WndProc(Message& m)
  at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
  at System.Windows.Forms.ContainerControl.WndProc(Message& m)
  at System.Windows.Forms.Form.WmCreate(Message& m)
  at System.Windows.Forms.Form.WndProc(Message& m)
  at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
  at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
  at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,IntPtr lparam)

在这个最新的堆栈跟踪中,根本没有引用MaxTo,90%的崩溃是与上述类似的堆栈跟踪.

在网上阅读我发现如果你忘记释放或者处理变量,这个错误是平常的.当我看到我的WndProc,似乎有时候有问题通过,我找不到一个地方挂在任何对象的引用.除了一个变量之外,所有变量都是WndProc的本地变量,因此在方法终止时应该是垃圾回收.

protected override void WndProc(ref Message m)
{
    base.WndProc(ref m); // I'm assuming the first trace can be caught here
    IntPtr hwnd = m.WParam;
    // Our hook tells us something got maximized
    if (Win32Import.UWM_MAXIMIZE == (UInt32)m.Msg)
    {
        // Figure out if we are temporarily disabled or using alternative profiles
        KeyStateInfo keyState = KeyboardInfo.GetKeyState(Settings.AlternativeProfileKey);
        Rectangle r = FindRectangle(MousePosition,(Settings.EnableAlternativeProfile && keyState.IsPressed ? AlternativeRegions : Regions));
        // Did we find a rectangle to place it in?
        if (r != Rectangle.Empty)
        {
            Rectangle position = Win32Import.GetWindowRectangle(hwnd);
            Rectangle prevIoUsPos = GetLocation(hwnd);
            if (position == r && prevIoUsPos != Rectangle.Empty)
            {
                // We are restoring the original position
                Win32Import.SetWindowPos(hwnd,IntPtr.Zero,prevIoUsPos.X,prevIoUsPos.Y,prevIoUsPos.Width,prevIoUsPos.Height,Win32Import.SWP_NOZORDER | Win32Import.SWP_NOSENDCHANGING);
            }
            else
            {
                // We are maximizing to a region
                Win32Import.ShowWindow(hwnd,Win32Import.WindowShowStyle.Restore);
                Win32Import.SetWindowPos(hwnd,r.X,r.Y,r.Width,r.Height,Win32Import.SWP_NOZORDER | Win32Import.SWP_NOSENDCHANGING);
                // Make sure we remember this location
                RememberLocation(hwnd,position);
            }
        }
    }
    else if (MaxTo64WindowHandleMessage == m.Msg)
    {
        // Store the window handle of our 64-bit subprocess
        SubProcess64WindowHandle = m.WParam;
    }
}

即使在多天内运行程序,我也无法重现错误.

我的假设是系统在未分片的内存或GDI句柄上都很低,但是我无法在任何地方确认.这个错误似乎没有任何好的文档.

有什么想法还可以吗?我可以做任何事情来防止这个错误吗?

更新:由于缺乏一个体面的解决方案,该问题重新打开了更多的堆栈跟踪.简单地忽略它并不能解决问题.

解决方法

泄漏或使用许多GDI对象/句柄.那些可能导致资源堆不足.您可能无法再现,因为您的用户可能会运行其他GDI资源重型程序或使用终端服务器,在这种情况下,他们必须与其他用户共享一些堆.见 System Error. Code: 8. Not enough storage is available to process this command

Here您可以阅读有关桌面堆监视器工具来诊断桌面堆问题.

Hereherehere是GDI泄漏检测工具.

猜你在找的C#相关文章