C# &引用;Win32Exception存储空间不足,无法处理此命令;作为windows服务运行时出错

C# &引用;Win32Exception存储空间不足,无法处理此命令;作为windows服务运行时出错,c#,.net,win32exception,C#,.net,Win32exception,有时我会出错 Win32Exception存储空间不足,无法处理此命令 应用程序运行大约一个月后 这与 通常,它作为Windows服务运行,更改其登录的用户仍然会导致错误发生。但是,如果我双击应用程序来运行它,它就可以正常工作。它可以作为Windows服务再次运行的唯一方法是重新启动服务器 该错误出现在应用程序写入的日志中。完全错误是: System.ComponentModel.Win32Exception: Not enough storage is available to process

有时我会出错

Win32Exception存储空间不足,无法处理此命令

应用程序运行大约一个月后

这与


通常,它作为Windows服务运行,更改其登录的用户仍然会导致错误发生。但是,如果我双击应用程序来运行它,它就可以正常工作。它可以作为Windows服务再次运行的唯一方法是重新启动服务器

该错误出现在应用程序写入的日志中。完全错误是:

System.ComponentModel.Win32Exception: Not enough storage is available to process this command
   at System.Windows.Forms.NativeWindow.WindowClass.RegisterClass()
   at System.Windows.Forms.NativeWindow.WindowClass.Create(String className, Int32 classStyle)
   at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   at System.Windows.Forms.Control.CreateHandle()
   at System.Windows.Forms.Application.MarshalingControl..ctor()
   at System.Windows.Forms.Application.ThreadContext.get_MarshalingControl()
   at System.Windows.Forms.WindowsFormsSynchronizationContext..ctor()
   at System.Windows.Forms.WindowsFormsSynchronizationContext.InstallIfNeeded()
   at System.Windows.Forms.Control..ctor(Boolean autoInstallSyncContext)
   at System.Windows.Forms.ScrollableControl..ctor()
   at System.Windows.Forms.ContainerControl..ctor()
   at System.Windows.Forms.Form..ctor()
   at LicensingModule.LicenseKeyValidator..ctor(String Name, String Path)
   at MIDICOMExporter.Program.Main(String[] args)
我看到其他答案说这与服务器上的内存泄漏有关,但如果双击应用程序仍然可以运行,这是否仍然意味着可能存在内存泄漏


此外,它正在Windows Server 2012上运行。

注册表类的调用导致内存错误。看见您的应用程序是否多次调用
RegisterClass
RegisterWindowMessage

是的,问题可能与服务器上的内存泄漏有关。也许是能量耗尽了。“非交互式”窗口会话的桌面堆与真实(交互式)桌面会话的桌面堆不同。这解释了为什么双击应用程序仍然是可能的

请尝试查找注册表项\System\CurrentControlSet\Control\Session Manager\SubSystem,并增加
SharedSection=xxx,yyy,zzz的第三个参数(zzz),如中所述(对于yyy)

第三个SharedSection值(512)是桌面堆的大小 对于与“非交互式”窗口关联的每个桌面 车站


如果这解决了您的问题,堆耗尽(例如由资源泄漏引起)很可能是问题的根源。默认情况下,“非交互式”桌面堆的大小比标准堆小得多。

“它可以作为Windows服务再次运行的唯一方法是重新启动服务器。”您的意思是重新启动服务吗?或者你的意思是你必须重新启动Windows服务器程序?我的意思是服务器必须关闭然后重新启动。在此之前重新启动服务不起作用。这听起来很奇怪。一个建议是:在让程序失败的同时试着运行ProcMon,看看它是否记录了任何可以提示问题所在的信息。我在问题中添加了完整的错误消息。我在应用程序日志中看到此消息。该服务似乎正在尝试设置Windows对话框。它是否设置了“允许服务与桌面交互”标志?(在服务控制面板中,右键单击服务,选择属性,然后选择“登录”选项卡。)我尝试使用atom表监视器()。看起来它说总共有800-900个原子被使用。这是否意味着问题不是因为原子耗尽?我没有尝试,因为代码中的内存泄漏被发现,但我喜欢解释为什么它不能作为服务运行,但在双击应用程序时仍然可以运行,所以我将此标记为答案。
System.ComponentModel.Win32Exception: Not enough storage is available to process this command
   at System.Windows.Forms.NativeWindow.WindowClass.RegisterClass()
   at System.Windows.Forms.NativeWindow.WindowClass.Create(String className, Int32 classStyle)
   at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   at System.Windows.Forms.Control.CreateHandle()
   at System.Windows.Forms.Application.MarshalingControl..ctor()
   at System.Windows.Forms.Application.ThreadContext.get_MarshalingControl()
   at System.Windows.Forms.WindowsFormsSynchronizationContext..ctor()
   at System.Windows.Forms.WindowsFormsSynchronizationContext.InstallIfNeeded()
   at System.Windows.Forms.Control..ctor(Boolean autoInstallSyncContext)
   at System.Windows.Forms.ScrollableControl..ctor()
   at System.Windows.Forms.ContainerControl..ctor()
   at System.Windows.Forms.Form..ctor()
   at LicensingModule.LicenseKeyValidator..ctor(String Name, String Path)
   at MIDICOMExporter.Program.Main(String[] args)