【发布时间】:2012-05-23 11:33:00
【问题描述】:
我的 Windows 应用程序崩溃了,因为后台线程正在尝试更新表单,即使在表单被处理后也是如此。我的代码如下
if (IsDisposed || dataGridIncidentView.IsDisposed)
return;
if (dataGridIncidentView.InvokeRequired)
{
dataGridIncidentView.Invoke(new MethodInvoker(delegate { rowIndex = dataGridIncidentView.Rows.Add("val1","val2"); }));
}
else
{
rowIndex = dataGridIncidentView.Rows.Add("val1", "val2");
}
事件日志中的错误是:
进程因未处理的异常而终止。例外 信息:System.InvalidOperationException 堆栈:在 System.Windows.Forms.DataGridViewRowCollection.AddInternal(布尔值, System.Object[]) 在 System.Windows.Forms.DataGridViewRowCollection.Add(System.Object[]) ..... ..... .....
我对 asyncCallBack 函数进行了 IsDisposed 检查。但是所有这些检查并没有处理所有情况。任何人都可以建议我,如何解决它?
谢谢,
阿比纳夫
【问题讨论】:
标签: c# .net winforms datagridview thread-safety