Aniket Narvankar

Aniket Narvankar

  • 562
  • 2.1k
  • 604.8k

C# Multithreading

Sep 28 2021 7:15 AM

In table 1 there are 150000 records,I have to compare each record from table 1 one by one with corresponding record in table 2,if match is found update the same record in table 1,if match is not found need to update Notes column value in table 1 to no matching record found.

For this I am fetching records from both tables in dt and dt1 respectively.

Following is the code I have done

DataTable dt = getRecordsfromTable1();
DataTable dt1 = getRecordsfromTable2();
foreach(DataRow dr in dt.Rows)
{
     foreach(DataRow dr1 in dt1.Rows)
     {
          if(dr["Id"].ToString() == dr1["Id"].ToString())
          {
               //Calling update method in Data Access Layer to Update record in First table
               Update(dr["Id"].ToString());
          }
          else
         {
             //Id not found
         }
     }
}

But this is working very slow as I am comparing 150000 records one by one. How to use multithreading concept over here to make processing faster,kindly guide me on the same.


Answers (2)