简体   繁体   中英

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

I have one problem when winform opening long time if I sent another request is giving Error creating window handle for flowlayout panel control clearing:

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

Error: ERROR OnExampleDTOReceived:Error creating window handle.-->-->System.ComponentModel.Win32Exception: Error creating window handle. 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:line 689 at PrxCustScr.Sockets.Listener.OnExampleDTOReceived(String message) in \Source\Workspaces\TestApplications\PrxCustScr\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.OnExampleDTOReceived(String message) in \Source\Workspaces\TestApplications\PrxCustScr\PrxCustScr\Sockets\Listener.cs:line 273

How can I solve this problem?

I solved with this code:

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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM