簡體   English   中英

當 flowlayoutpanel 控件在 c# 中清除時,創建 window 句柄時出錯?

[英]error creating window handle when flowlayoutpanel controls clear in c#?

如果我發送另一個請求,winform 長時間打開時我會遇到一個問題,錯誤是為 flowlayout 面板控制清除創建 window 句柄:

 flw.Invoke(new Action(() => flw.Controls.Clear()));

錯誤:錯誤 OnExampleDTOReceived:創建 window 句柄時出錯。-->-->System.ComponentModel.Win32Exception:創建 window 句柄時出錯。 at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous) at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args) at PrxCustScr.Sockets.Listener .EndTrx(String data, FlowLayoutPanel flw) in \Source\Workspaces\TestApplications\PrxCustScr\PrxCustScr\Sockets\Listener.cs: PrxCustScr.Sockets.Listener.OnExampleDTOReceived(String message) 中的第 689 行\PrxCustScr\Sockets\Listener.cs:line 273--> at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous) at System.Windows.Forms.Control.Invoke( D elegate method, Object[] args) at PrxCustScr.Sockets.Listener.EndTrx(String data, FlowLayoutPanel flw) in \Source\Workspaces\TestApplications\PrxCustScr\PrxCustScr\Sockets\Listener.cs:line 689 at PrxCustScr.Sockets.Listener. \Source\Workspaces\TestApplications\PrxCustScr\PrxCustScr\Sockets\Listener.cs 中的 OnExampleDTOReceived(字符串消息):第 273 行

我怎么解決這個問題?

我用這段代碼解決了:

http://www.codeease.com/windows-form-flowlayoutpanel-memory-leak.html

for(int i = flowlayoutpanel1.Controls.Count-1; i >= 0; --i)
{ 
   var ctl = flowlayoutpanel1.Controls[i];
    ctl.Dispose();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM