"Start may not be called on a task that has completed" exception on task that did not start
<p>I am working on a mobile application developed with Xamarin, and every now and then I am receiving reports in which the application crashes because of the following exception:</p>

<blockquote>
  <p>System.InvalidOperationException Start may not be called on a task that has completed.</p>
</blockquote>

<p>In order to be clear, this is more or less the structure of the function where this happens:  </p>

<pre><code>    CancellationTokenSource tokenSource;

    void Function(bool condition1, bool condition2)
    {
        if (tokenSource != null)
        {
            tokenSource.Cancel();
            tokenSource.Dispose();
            tokenSource = null;
        }

        Task completionTask = null;

        if (condition1)
        {
            tokenSource = new CancellationTokenSource();
            completionTask = new Task(async () =&gt;
                {
                    await Task.Delay(1000);
                    if (tokenSource != null &amp;&amp; !tokenSource.IsCancellationRequested)
                    {
                        InvokeOnMainThread(Function2);
                    }
                }, tokenSource.Token);
        }

        if (condition2)
        {
            TaskFactory.StartNew(() =&gt;
                {
                  ...
                }).ContinueWith(() =&gt;
                {
                    if (completionTask != null)
                    {
                        completionTask.Start();
                    }
                });
        }
        else
        {
            if (completionTask != null)
            {
                completionTask.Start();
            }
        }
    }

    void Function2()
    {
        if (tokenSource != null)
        {
            tokenSource.Cancel();
            tokenSource.Dispose();
            tokenSource = null;
        }
    }
</code></pre>

<p>I cannot manage to reproduce the bug, and also I am not sure how is it possible that <code>completionTask</code> has been already started, as it can be started only once. Even if, for any reason,  <code>Function</code> is called in sequence, or by multiple threads, this shouldn't cause any issue, as <code>completionTask</code> is a local variable. </p>

<p>Any idea about what could be the cause?</p>