title: assistance with optimization
body: <p>not sure if stackoverflow is normally used for stuff like this but i'm looking for assistance in optimizing my code. I am running a method to query a count from a database which is fast and works fine. and a timer that is set to run this every 5 minutes. When i implement the timer in my main window after initialization it freezes when opening the window for 30+ seconds. It didn't do that before I added the timers. Any help optimizing this or tips on improving the way this works would be great!</p>
  
  <p>Method that runs SQL query:</p>
  
  <pre><code>public string SQLDataTotalCalls()
          {
              DateTime dte = DateTime.Today;
  
              string fixedStartDate = String.Format("{0:yyyy-MM-dd " + "05:00:00.000" + "}", dte);
              string fixedEndDate = String.Format("{0:yyyy-MM-dd " + "05:00:00.000" + "}", dte.AddDays(1));
  
              SqlConnection connection = null;
  
              using (connection)
              {
                  try
                  {
                      var dataSet = new DataSet();
  
                      connection = new SqlConnection("Data Source=QL1OADB1;Initial Catalog=OADB;User Id=;Password=");
                      connection.Open();
  
                      var command = new SqlCommand("SELECT COUNT(SOURCEID) AS 'MYCOUNT' "
                                                   + "FROM [OADB].[oadb].[CmsCallHistory] "
                                                   + "WHERE disposition = 2 and DISPSPLIT in (" + SkillNumber + ") AND SEGSTOP BETWEEN '" + fixedStartDate + "' and '" + fixedEndDate + "'",
                          connection)
                      {
                          CommandType = CommandType.Text
                      };
  
                      var dataAdapter = new SqlDataAdapter { SelectCommand = command };
  
                      dataAdapter.Fill(dataSet);
  
                      return dataSet.Tables[0].Rows[0]["MYCOUNT"].ToString();
  
                  }
                  catch (Exception e)
                  {
                      throw new Exception(e.Message, e);
                  }
                  finally
                  {
                      if (connection != null)
                      {
                          connection.Close();
                      }
                  }
              }
          }
  </code></pre>
  
  <p>Timer that triggers the method every 5 minutes:</p>
  
  <pre><code>public async Task RunPeriodicQueryTotalCalls()
          {
              TimeSpan interval = TimeSpan.FromMinutes(5);
  
              while (true)
              {
                  await Task.Delay(interval);
  
                  string result = await Task.Run((Func&lt;string&gt;)SQLDataTotalCalls);
  
                  TotalDailyCalls = result;
              }
          }
  </code></pre>
  
  <p>This is where i initialize the window. please note that I run these querys also when the application first launches before the timer runs otherwise the numbers will not post until it runs 5 minutes later:</p>
  
  <pre><code>public ScoreBoardBigViewWindow()
          {            
              InitializeComponent();            
  
              string value = "Enter Skill Number Here";
              if (Tmp.InputBox("New document", "New document name:", ref value) == System.Windows.Forms.DialogResult.OK)
              {
                  SkillNumber = value;
              }
  
              TotalDailyLast7Days = SQLDataSevenPastCalls();
              TotalDailyCalls = SQLDataTotalCalls();
              TotalDailyAbandon = SQLDataAbandonCalls();           
  
              RunPeriodicQueryTotalCalls();
              RunPeriodicQueryAbandonCalls();
          }
  </code></pre>
  
  <p>If i remove RunPeriodicQueryTotalCalls(); and RunPeriodicQueryAbandonCalls(); then the performance issue goes away.</p>
  
  <p>If stackoverflow is not the right place to ask this type of question please let me know and I'll reach out to other avenues for further assistance. </p>