C#DataGridView DataTable内部索引在并行循环中损坏

时间:2018-08-12 20:16:35

标签: c# datagridview parallel-processing

有一个带有加密值的隐藏列,我想将这些值复制并解密到另一列,为加快此过程,我使用了并行for循环,但是当我尝试使用它时,它仅在我的台式机上工作我的笔记本出现以下错误:

  

DataTable内部索引已损坏:“ 5”

     

DataTable内部索引已损坏:“ 13”

public void LoadKeyStarter()
{
    DataTable dt;
    DataSet DS = new DataSet();
    mySqlDataAdapter.Fill(DS);
    dt = DS.Tables[0];
    dt.Columns.Add("Decrypted", typeof(System.String));
    keystoregridview.DataSource = dt;

    LoadKeyColumn = new Thread(LoadKeyColumnValues);

    LoadKeyColumn.Start();
}

public void LoadKeyColumnValues()
{
     try
     {
         #NOT WORKING ON NB
         Parallel.For(0, keystoregridview.Rows.Count, i =>
         {
             keystoregridview.Rows[i].Cells["Decrypted"].Value = Decrypt(keystoregridview.Rows[i].Cells["Encrypted"].Value.ToString());
         });

         /* WORKING BOTH
         for (int i = 0; i < keystoregridview.Rows.Count; i++)
         {
             keystoregridview.Rows[i].Cells["Decrypted"].Value = Decrypt(keystoregridview.Rows[i].Cells["Encrypted"].Value.ToString());
         }*/
     }
     catch (Exception _ex)
     {
         MessageBox.Show(_ex.ToString());
     }
}

有什么解决办法吗?

0 个答案:

没有答案