Opacity = 1%有时会产生Win32Exception:没有足够的存储空间来处理此命令

San*_*upe 1 .net c#

我们的一个WinForm在Form.Show上给出了以下异常.表单的不透明度设置为1%.我们观察到,如果我们将Opacity设置为100%,则错误消失.当机器(非应用程序)长时间运行而没有重新启动时,通常会出现错误,通常在2天后发生.

例外详情如下:

System.ComponentModel.Win32Exception: Not enough storage is available to process this command
   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, Int32 msg, IntPtr wparam, IntPtr lparam)
MessageNot enough storage is available to process this command
StackTrace   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, Int32 msg, IntPtr wparam, IntPtr lparam)SourceSystem.W indows.Forms
Run Code Online (Sandbox Code Playgroud)

Han*_*ant 9

System.ComponentModel.Win32Exception:没有足够的存储空间可用于处理此命令

这是一个非常低级别的Windows错误,它通常表示内核内存池已耗尽.这通常不会将托管代码指向问题的根源,尽管在Winforms应用程序中泄漏窗口句柄非常容易.首先检查,运行Taskmgr.exe,切换到进程选项卡.查看+选择列并勾选句柄,用户对象和GDI对象.在程序运行时观察这些列.特别是如果USER Objects继续攀爬,那么您的代码就会出现可能触发此异常的错误.到目前为止,最常见的泄漏窗口句柄的方法是使用Controls.Clear()或Controls.Remove()并忘记在您删除的控件上调用Dispose()方法.那些被删除的控件只会累积在隐藏的"停车窗口"上,永远不会被释放.

如果这没有成功,那么您正在查看机器的问题.视频驱动程序是问题的最可能来源.它主要涉及TransparencyKey和Opacity属性,它是实现效果的视频适配器.当然,如果您的程序立即对此异常进行轰炸而不是仅在运行一段时间之后,这是一个领先指标.这个问题并不清楚.寻找驱动程序更新是合乎逻辑的下一步.