创建窗口句柄时出错

我已经编写了一个客户端 – 服务器c#app并让它整夜运行,当我想看它是否仍在工作时,我发现服务器上有错误。 不幸的是,应用程序是很大的粘贴在一些代码,但我得到一个错误

Application.Run(form1中)

在program.cs中说 替代文字

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

代表按钮无法执行

来自这个代码,并且mai参与了这个错误(这段代码在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,进程选项卡进行诊断。 查看+选择列并勾选USER对象。 在进程运行时观察该进程的值。 它应该稳步攀升。 当它达到10,000时,你的程序将使用此exception进行轰炸。

这是因为没有在您自己从Controls集合中删除的控件上调用Dispose(),无论是通过调用Remove()还是Clear()。

听起来像你的应用程序试图访问受保护的数据。 请记住,当您的系统由于不活动/注销而锁定时,您的应用程序将无法与系统的某些方面进行交互。 这样的例子是试图抓住窗户的把手或拍摄屏幕截图。 这些都会引发错误。

从foreach语句中调用静态类方法时,我收到同样的错误。 用户对象计数继续增加,并且在程序结束或发生错误之前未释放。

我将静态方法更改为实例方法,用户对象保持为60。

 //created and instance of the object var oIP = new ImportProvider(); foreach(var patient in lstPatients) { var oP = PatientConversionProvider.GetPatient(oPatient.RecordId); if(oP != null) { //referenced the instance member (changed from a static member) if(oIP.ImportDataIntoSmartRx(oP)) { successCount++; lstMrNumber.Add(oPatient.MrNumber); } totalCount++;