title: Keeping responsive UI
body: <p>I have a winform which have several combo boxes and a gridview.</p>
  
  <p>Initially I am creating the gridview with Rows and Columns and no data filled in with.</p>
  
  <p><img src="https://i.stack.imgur.com/mXL8D.jpg" alt="enter image description here"></p>
  
  <p>The filling data to grid is a long running task which will loop through all rows and read column header and depending on that it will apply different color and data to each cell.</p>
  
  <p>What I am trying to achieve is to load the grid as above in form load event, and after the form loaded start filling data to grid so user can see what happening. Same things apply to the combo box value change since I will load data according to the combo value.</p>
  
  <p>What I have tried is something like this...</p>
  
  <p>In form load I am calling method </p>
  
  <pre><code> private void LoadForm()
          {                        
              DataBind(); // this will load the initial grid without cell data            
  
              this.BeginInvoke((MethodInvoker)this.LongRunningProcess1);
  
              this.BeginInvoke((MethodInvoker)this.LongRunningProcess2);
  
           }
  </code></pre>
  
  <p>But still it taking long time and I don't have the responsive UI.</p>
  
  <p>I also tried something like this but no luck....</p>
  
  <pre><code>            ThreadStart ts = LongRunningProcess1;
              Thread t1 = new Thread(ts);
              t1.Start();
  </code></pre>
  
  <p>Also using a background worker to complete the long running operation causes <strong><em>"Cross thread operation"</em></strong> issue.</p>
  
  <pre><code> private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
          {
                  LongRunningProcess1();
                  LongRunningProcess2();           
          }
  </code></pre>
  
  <p>Any help to make this working is appreciate..</p>
  
  <p>Thanks </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I found a really cool solution <a href="http://www.codeproject.com/Articles/52752/Updating-Your-Form-from-Another-Thread-without-Cre" rel="nofollow noreferrer">Updating Your Form from Another Thread without Creating Delegates for Every Type of Update</a></p>
  
  <p>Thanks for the answers!!!</p>