title: How to handle IO-heavy workload at WPF Application startup
body: <p>I'm currently trying to write a simple C#-WPF-Application that functions as a simple universal 'launcher'. For different applications we program.</p>
  <p>It's purpose is to check the current software version of the 'real' software and if a new one is available it starts to copy the installer from a network share and runs the installer afterwards.
  Then it starts the 'real' application and thats it.</p>
  <p>The user Interface mainly consists of a startup window which shows the user the currently executed action (version check, copy, installation, startup, ...).</p>
  <p>Now I create my view and my viewModel in the overridden StartUp method in App.cs</p>
  <pre><code>public override OnStartup(string[] args)
  {
      var viewModel = new StartViewModel();
      var view = new StartView();
  
      view.DataContext = viewModel;
  
      view.Show();
  
      // HERE the logic for the Launch starts
      Task.Run(() =&gt; Launch.Run(args));
  }
  </code></pre>
  <p>The problem is that if I don't go async here the Main Thread is blocked and I cannot update the UI. Therefore I got it working by using the <code>Task.Run(...)</code>. This solves my problem of blocking the UI thread, but I have some problems/questions with this:</p>
  <ol>
  <li>I cannot await the task, because that would block the UI again. Where to await it?</li>
  <li>Is my concept of starting this workflow here ok in the first place?</li>
  </ol>
  <hr />
  <p>Some update to clarify: After I show the UI to the user my logic starts to do heavy IO stuff. The possible calls I came up with are the following 3 variants:</p>
  <pre><code>view.Show();
  
  // v1: completely blocks the UI, exceptions are caught
  DoHeavyIOWork();
  
  // v2: doesn't block the UI, but exceptions aren't caught
  Task.Run(() =&gt; DoHeavyIOWork());
  
  // v3: doesn't block the UI, exceptions are caught
  await Task.Run(() =&gt; DoHeavyIOWork());
  </code></pre>
  <p>Currently I'm not at my work PC so i apologies for not giving you the original code. This is an on the fly created version.</p>
  <p>I guess v1 and v2 are bad because of exceptions and the UI blocking.</p>
  <p>I thought v3 didn't work when I tried it in my office. Now it seems to work in my local example. But I'm really not sure about v3. Because I'm using <code>async void StartUp(...)</code> there. Is it okay here?</p>