gpt4 book ai didi

c# - 创建窗口句柄时出错

转载 作者:太空宇宙 更新时间:2023-11-03 17:28:01 49 4
gpt4 key购买 nike

我编写了一个客户端-服务器 C# 应用程序并让它运行了一整夜,当我想看看它是否仍在工作时,我发现服务器上有一个错误。不幸的是,该应用程序太大,无法粘贴一些代码,但我在

Application.Run(form1)

在 program.cs 中说 alt text

可以忽略前两个消息框(从左到右),因为它们应该显示,但另一个

delegate buton couldn't be executed

来自这段代码并且可能参与了这个错误(这段代码在 form1.cs 中):

public void setButonState(inout_buton b, bool t, int q,int contor)
{
try
{
if (b.InvokeRequired)
{
Callback d = new Callback(setButonState);
this.Invoke(d, new object[] { b, t, q, contor });
}
else
{
b.Enabled = t;
if (q == 0) b.setBackgroundGrey();
if (q == 1) b.setBackgroundGreen();
if (q == 2) b.setBackgroundRed();
if (q == 3) b.setBackgroundOrange();

b.setSecondaryLabel(contor);

}
}
catch { new ShowMessageBox("FORM1 : delegate buton couldn't be executed"); }

}

我的问题是:在什么情况下会出现这些错误?

最佳答案

使用 Taskmgr.exe 的“进程”选项卡对此进行诊断。查看 + 选择列并勾选用户对象。在流程运行时观察该流程的值。它应该稳步攀升。当它达到 10,000 时,您的程序将因该异常而崩溃。

这是由于您没有通过调用 Remove() 或 Clear() 对您自己从 Controls 集合中删除的控件调用 Dispose() 造成的。

关于c# - 创建窗口句柄时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4752481/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com