title: WPF 4.5: How to create child thread and continue task to UI main thread?
body: <p>I use WPF 4.5 and MVVM Caliburn Micro and have following WPF code:</p>
  
  <pre><code>public class MainViewModel: Screen
  {
      public MainViewModel()
      {
          if (!ConnectServer())
          {
              Console.WriteLine("Connection failed");
              return;
          }
          // Following method can only be run if server connection established
          ProcessThis();
      }
  }
  </code></pre>
  
  <p>My code above has only one chance to connect and if it is failed it shows the view and do nothing. If I use while(!ConnectServer()) it will block the UI thread all the time, means nothing will be displayed to user while the connection is still failed.It is very ugly.</p>
  
  <p>What I want: </p>
  
  <ol>
  <li>if the connection is failed, means ConnectServer() returns false, it should wait for 10 seconds and try to connect again and again (eg. call a method RetryConnect()) till it is successful <strong>WITHOUT blocking</strong> the UI thread.</li>
  <li><strong>And</strong> after it is connected, it should continue to main thread and run ProcessThis().</li>
  </ol>
  
  <p>Theoretically I know it needs background separated thread, but I don't know how to implement it simple and good. Please feel free to use my sample code to explain. Thank you in advance.</p>