【问题标题】:DataGridView error : The process was terminated due to an unhandled exceptionDataGridView 错误:进程因未处理的异常而终止
【发布时间】: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


    【解决方案1】:

    您需要在委托内部进行IsDisposed 检查。

    IE:

    delegate { 
      if (!IsDisposed) rowIndex = dataGridIncidentView.Rows.Add("val1","val2"); 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-08
      相关资源
      最近更新 更多