【问题标题】:error creating window handle when flowlayoutpanel controls clear in c#?在 C# 中清除 flowlayoutpanel 控件时创建窗口句柄时出错?
【发布时间】:2020-11-02 08:49:37
【问题描述】:

如果我发送另一个请求,winform 长时间打开时会出现一个问题,错误是为 flowlayout 面板控件清除创建窗口句柄:

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

错误: ERROR OnExampleDTOReceived:创建窗口句柄时出错。-->-->System.ComponentModel.Win32Exception:创建窗口句柄时出错。 在 System.Windows.Forms.Control.MarshaledInvoke(控制调用者,委托方法,对象 [] 参数,布尔同步) 在 System.Windows.Forms.Control.Invoke(委托方法,对象 [] 参数) 在 \Source\Workspaces\TestApplications\PrxCustScr\PrxCustScr\Sockets\Listener.cs 中的 PrxCustScr.Sockets.Listener.EndTrx(字符串数据,FlowLayoutPanel flw):第 689 行 在 \Source\Workspaces\TestApplications\PrxCustScr\PrxCustScr\Sockets\Listener.cs 中的 PrxCustScr.Sockets.Listener.OnExampleDTOReceived(字符串消息):第 273 行--> 在 System.Windows.Forms.Control.MarshaledInvoke(控制调用者,代表方法,Object[] args,布尔同步) 在 System.Windows.Forms.Control.Invoke(委托方法,对象 [] 参数) 在 \Source\Workspaces\TestApplications\PrxCustScr\PrxCustScr\Sockets\Listener.cs 中的 PrxCustScr.Sockets.Listener.EndTrx(字符串数据,FlowLayoutPanel flw):第 689 行 在 \Source\Workspaces\TestApplications\PrxCustScr\PrxCustScr\Sockets\Listener.cs 中的 PrxCustScr.Sockets.Listener.OnExampleDTOReceived(字符串消息):第 273 行

我该如何解决这个问题?

【问题讨论】:

  • 从 cmd.exe 检查客户端和服务器的连接状态 >Netstat -a 将提供端口号列表和连接状态。连接可能正在关闭,因此请检查工作和不工作的时间。

标签: c# sockets event-handling flowlayoutpanel


【解决方案1】:

我用这段代码解决了:

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

【讨论】:

    猜你喜欢
    • 2013-12-10
    • 2011-10-17
    • 1970-01-01
    • 2017-05-02
    • 2013-01-30
    • 2013-06-02
    • 2017-09-25
    相关资源
    最近更新 更多