title: populate datagridview with thread c#
body: <p>Im trying to populate a datagridview from a query of sql but it takes a long time , what im trying to do is show a .gif "loading" meanwhile is populating the grid, im using threads but the .gif freezes , and if I use the  <code>CheckForIllegalCrossThreadCalls = false;</code>  the datagridview doesnt load the scroll bar  acts weird. here is my code</p>
  
  <pre><code>delegate void CambiarProgresoDelegado(); 
  </code></pre>
  
  <p>BUTTON CLICK</p>
  
  <pre><code> private void btn_busca_Click(object sender, EventArgs e)
      {
          pictureBox1.Visible = true;
         thread=  new Thread(new ThreadStart(ejecuta_sql));
          thread.Start();
      }
  </code></pre>
  
  <p>method</p>
  
  <pre><code>private void ejecuta_sql()
      {
  
  if (this.InvokeRequired)
          {         
  
           CambiarProgresoDelegado delegado = new CambiarProgresoDelegado(ejecuta_sql);
  
          object[] parametros = new object[] { };
            this.Invoke(delegado, parametros);
         }
          else
          {
              myConnection.Open();
              SqlCommand sql_command2;
              DataSet dt2 = new DataSet();
  
              sql_command2 = new SqlCommand("zzhoy", myConnection);
              sql_command2.CommandType = CommandType.StoredProcedure;
              sql_command2.Parameters.AddWithValue("@FechaIni", dateTimePicker1.Value.ToShortDateString());
              sql_command2.Parameters.AddWithValue("@FechaFin", dateTimePicker2.Value.ToShortDateString());
              SqlDataAdapter da2 = new SqlDataAdapter(sql_command2);
              da2.Fill(dt2, "tbl1");
              grid_detalle.DataSource = dt2.Tables[0];
              myConnection.Close();
              pictureBox1.Visible = false;
  
  
          }
  </code></pre>
  
  <p>and the .gif freezes until the thread finish his job.</p>