title: c# Async task running with return value for a function with parameters
body: <p>So I've searched the Net for ways of executing some heavy tasks async to keep the UI responsive. And to be quite honest - I did not find anything that describes my actual situation in a way <em>I can understand</em>.</p>
  
  <p>So I have this code snippet:</p>
  
  <pre><code>List&lt;myType&gt; indexedItems = new List&lt;myType&gt;();           
  Task t = new Task.Run(() =&gt; indexedItems = FileHandling.ReadIndexFile(downloadPath));
  lblProgress.Content = "Reading index file...";
  lstItems.ItemsSource = null;
  t.Wait();
  </code></pre>
  
  <p>What I actually want is to run the <code>ReadIndexFile</code> function with the paramether <code>downloadPath</code> to write the value of <code>indexItems</code> while allowing me to repaint and alter the UI and then wait for the Task to finish.</p>
  
  <p>I've ran into so many problems with that piece of code that I just ask for an example for this particular scenario and a brief explanation.</p>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>EDIT
  Original snippet with plain old sync. execution to show what happens:</p>
  
  <pre><code>if (File.Exists(downloadPath + @"\index.sbmdi"))
          {
              lblProgress.Content = "Reading index file...";
              lstMangas.ItemsSource = null;
              indexedMangas = FileHandling.ReadIndexFile(downloadPath);
              categoryList = Library.BuildCategoryList(indexedMangas);
  
              lstMangas.ItemsSource = indexedMangas;
              lblProgress.Content = "Ready.";
          }
  lblProgress.Content = "Ready.";
  prgrssUpper.IsIndeterminate = false;
  </code></pre>
  
  <p>Then there are some UI updates in another method which are not related to this data, just updating labels, buttons, etc.</p>