title: C# windows show loading GIF while updating the form GUI from database
body: <p>Application Description:<br>
  Developed a small windows MDI application in C# where multiple users update and scan product bar codes before dispatching. We are using SQL as a database.</p>
  
  <p>Activity:<br>
  The supervisors have form named dashboard in the application where they can check multiple count details like scanning done by each user, daily scan count, hourly scan count, product scan count etc.</p>
  
  <p>Done:<br>
  I have used multiple list-views and labels to display this details successfully.</p>
  
  <p>Requirement:<br>
  The database contains millions of scanning records. I am using multiple stored procedures to update the list view and labels. Loading the same takes time. I want to show an animated GIF in picture box while the loading is being done in the background. </p>
  
  <p>I tried using threading and background worker but updating multiple controls like list view and labels on the master GUI doesn't look feasible [cross-threading]. Is this the only way to achieve this, Please direct me in the right direction. </p>
  
  <pre><code>        string queryString = "select scanby,count(distinct refno),count(1) from SecRec where scan='Y' and convert(varchar(10),ScanTime,111) like '" + comboDate + "' group by scanby order by 3,2 desc";
          lstVUser.Clear();
  
          lstVUser.Columns.Add("User", 105);
          lstVUser.Columns.Add("Cust", 60);
          lstVUser.Columns.Add("Imp", 60);
  
          using (SqlConnection conn = new SqlConnection(connectString))
          {
              SqlCommand cmd = new SqlCommand(queryString, conn);
              try
              {
                  conn.Open();
                  SqlDataAdapter adp = new SqlDataAdapter(queryString, conn);
                  DataTable dt = new DataTable();
                  adp.Fill(dt);
                  for (int i = 0; i &lt; dt.Rows.Count; i++)
                  {
                      DataRow dr = dt.Rows[i];
                      ListViewItem listitem = new ListViewItem(dr[0].ToString());
                      listitem.SubItems.Add(dr[1].ToString().PadLeft(3));
                      listitem.SubItems.Add(dr[2].ToString().PadLeft(3));
                      lstVUser.Items.Add(listitem);
                  }
              }
              catch (Exception ex)
              {
                  MessageBox.Show(ex.Message);
              }
          }
  </code></pre>