title: C# and Tasks - UI Thread Hang - Pre-Async/Await keywords
body: <p>I'm trying to understand what the correct code to grab a set of data asynchronously when I do not have access to the client lib I am using to retrieve the data. I specify an endpoint and a date range and I'm supposed to retrieve a list of playlists. What I have now never comes back after the Start() call. Note: this is running in a WinForm. I am trying to better understand Tasks and don't just want to jump to awaits or a BackgroundWorker. I know I'm getting lost somewhere.</p>
  
  <pre><code>    private void GoButtonClick(object sender, EventArgs e)
      {
          string baseUrl = "http://someserver/api";
          var startDateTime = this._startDateTimePicker.Value;
          var endDateTime = this._endDateTimePicker.Value;
          _getPlaylistsFunc = delegate()
              {
                  var client = new PlaylistExportClient(baseUrl);
                  return client.GetPlaylistsByDateRange(startDateTime, endDateTime).ToList();
              };
          var task = new Task&lt;List&lt;Playlist&gt;&gt;(_getPlaylistsFunc);
          task.ContinueWith((t) =&gt; DisplayPlaylists(t.Result));
          task.Start();
      }
  
      private void DisplayPlaylists(List&lt;Playlist&gt; playlists)
      {
          _queueDataGridView.DataSource = playlists;
      }
  </code></pre>
  
  <p><strong>UPDATE</strong>
  I made these changes but now the application seems to hang the UI thread.</p>
  
  <pre><code>    private void GoButtonClick(object sender, EventArgs e)
      {
          string baseUrl = "http://someserver/api";
          var startDateTime = this._startDateTimePicker.Value;
          var endDateTime = this._endDateTimePicker.Value;
          var token = Task.Factory.CancellationToken;
  
          var context = TaskScheduler.FromCurrentSynchronizationContext();
          Task.Factory.StartNew(() =&gt;
              {
                  var client = new PlaylistExportClient(baseUrl);
                  _queueDataGridView.DataSource = client.GetPlaylistsByDateRange(startDateTime, endDateTime).ToList();
  
              },token,TaskCreationOptions.None,context);
  
      }
  </code></pre>