title: C# large Linq query freezing Winform UI
body: <p>I am creating an application that compare two databases together one being an oracle database the other being a MySQL database. After it compares the two databases it will then move any data over that the MySQL database is missing into the MySQL database. It then updates to a visual monitor to tell the end user that data has been moved over.</p>
  
  <p>I have no trouble getting the compare done and moving the new lines over but I believe the LINQ query I am using is causing the winform UI to freeze up for almost a minute and a half. The databases contain anywhere between 18,000 - 25,000 lines each.  </p>
  
  <p>The query looks like this: </p>
  
  <pre><code>var matched = from table1 in oClone.AsEnumerable()
                                join table2 in mClone.AsEnumerable() on table1.Field&lt;decimal&gt;("CASEID") equals table2.Field&lt;Int64&gt;("CASEID")
                                where table1.Field&lt;decimal&gt;("CASEID") == table2.Field&lt;Int64&gt;("CASEID") || 
                                table1.Field&lt;string&gt;("CASENAME") == table2.Field&lt;string&gt;("CASENAME") || 
                                table1.Field&lt;DateTime&gt;("CREATEDDATE") == table2.Field&lt;DateTime&gt;("CREATEDDATE") || 
                                table1.Field&lt;int&gt;("STUDYMODEID") == table2.Field&lt;int&gt;("STUDYMODEID") || 
                                table1.Field&lt;string&gt;("ENVIRONMENT") == table2.Field&lt;string&gt;("ENVIRONMENT")
                                select table1;
                  var missing = from table1 in oClone.AsEnumerable()
                                where !matched.Contains(table1)
                                select table1;
  
                  missingLines = missing.CopyToDataTable();
                  AddNewLines(missingLines);   
  </code></pre>
  
  <p>Is there any way that I could optimize the query to stop the freezing of the UI?</p>