2013-06-12 82 views
1

我們的WinForm之一在Form.Show中給出了以下異常。表格的不透明度設置爲1%。我們觀察到,如果我們將不透明度設置爲100%,則錯誤消失。當機器(不是應用程序)長時間運行而沒有重新啓動時,通常會出現錯誤,一般在2天后。不透明度= 1%有時會給出Win32Exception:沒有足夠的存儲空間來處理此命令

異常詳情如下:

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 
+0

在我看來,真正的問題是在別的地方。如果您的應用程序運行很長時間,在發生錯誤之前,那麼很可能是某些資源沒有正確處理。垃圾收集器很好,但它本身並不能解決所有問題。 – ElmoVanKielmo

+0

感謝ElmoVanKielmo的回覆。根據觀察,問題似乎只與不透明度有關。當我們做出1%的問題出現時,當我們把它做成100%時,就會出現問題。 – SantoshTupe

+0

你說的是1%和100%,你嘗試過不同的價值嗎?因爲我猜100%不做任何事情,因爲它是默認設置... –

回答

8

System.ComponentModel.Win32Exception:沒有足夠的存儲是可用來處理此命令

這是一個非常低級的Windows錯誤,它通常表示內核內存池已耗盡。這通常不會指向託管代碼作爲問題的根源,儘管在Winforms應用程序中泄漏窗口句柄是非常容易的。首先檢查,運行Taskmgr.exe,切換到進程選項卡。查看+選擇列並勾選句柄,USER對象和GDI對象。程序運行時觀察這些列。特別是如果USER對象只是持續攀升,那麼你的代碼有一個可能觸發這個異常的錯誤。到目前爲止,最典型的泄漏窗口句柄的方法是使用Controls.Clear()或Controls.Remove(),並忘記在您刪除的控件上調用Dispose()方法。那些被刪除的控件只能在隱藏的「停車窗口」上累積,並且永遠不會被釋放。

如果這不能平移,那麼你正在看你的機器有問題。視頻驅動程序是問題最可能的來源。它主要涉及TransparencyKey和Opacity屬性,它是實現該效果的視頻適配器。當然,如果你的程序立即炸燬這個異常,而不是在運行一段時間之後,這個領先指標。這個問題並不清楚。尋找驅動程序更新是合乎邏輯的下一步。

+0

漢斯帕薩特,您好,非常感謝您的回覆。 1.我們檢查了用戶對象,他們正在增加和減少形式關閉,所以這可能不是問題。 2.系統剛啓動時,初始運行很少,不會出現問題。但是它會在幾個小時後開始,一旦它開始到來,它就會在每一次運行中出現。 – SantoshTupe

+1

這可能是吞噬內核內存空間的另一個過程。沒有足夠的時間讓你的程序去做它需要做的事情。你需要仔細看看機器上運行的是什麼。 SysInternals的Process Explorer是一個非常好的工具,可以提供深入的洞察力。 –

相關問題