title: implementing retry with backoff in Portable class library
body: <p>I am developing a <code>protable class library(PCL)</code>. the goal of this <code>PCL</code> is registering a push notification channel and also initiating a <code>MQTT</code> connection with server. the problem is that the <code>PCL</code> must be able to detect transient connection fault and retry with backoff. I find a library called <code>Polly</code> for this purpose. <code>PCL</code> has a static method (<code>Init</code>) that my <code>Windows Universal 8.1 app</code> called it from <code>OnLaunched</code> method. I want to the PCL doesn't block the <code>UI Thread</code>.I can't use <code>ConfigureAwait(false)</code> in <code>OnLaunched</code> method because only <code>UI Thread</code> can access elements that related to <code>UI</code>. I think Current <code>Polly</code> async implementation blocks <code>UI Thread</code></p>
  
  <p>what is correct way for implementing my PCL library with this assumption? is there a library for retry Purose in <code>PCL</code> except <code>Polly</code>?</p>
  
  <h2>App.xaml.xs</h2>
  
  <pre><code>    protected override async void OnLaunched(LaunchActivatedEventArgs e)
      {
          // some code
  
          await Notifier.Init(some parameters);
  
          // if I use ConfigureAwait(false) I see exceptions in rest of method
          // some code
      }
  </code></pre>
  
  <h2>PCL.cs</h2>
  
  <pre><code>public sealed class Notifier
  {
  
      public static async Task&lt;bool&gt; Init(some parameters)
      {
  
          Policy policy = Policy.Handle&lt;NullReferenceException&gt;().WaitAndRetryAsync(5,
                                 retryAttempt =&gt; TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (exception,timeSpan) =&gt;
                                 {
                                     Debug.WriteLine(exception);
                                     Debug.WriteLine(timeSpan);
                                 });
  
          policy.ExecuteAsync(() =&gt; instance.OpenChannelAndUploadAsync(instance.ServerUrl));
  
          await instance.InitiateMqtt();
  
  
          return true;
      }
  </code></pre>