title: Programmatically dismiss a MessageDialog
body: <p>On Windows Phone 8.1, how to programmatically dismiss a MessageDialog after the ShowAsync call?</p>
  
  <p>I’ve tried calling IAsyncInfo.Close(), it just throws an InvalidOperationException "An illegal state change was requested".</p>
  
  <p>I’ve tried calling IAsyncInfo.Cancel(). The dialog stays visible, the only result - after I tap the “Close” button, TaskCancelledException is marshaled to the awaiting routine.</p>
  
  <p><strong>Update:</strong> exact behavior depends on the sequence of the calls.</p>
  
  <ol>
  <li>If <code>IAsyncOperation.Cancel()</code> is invoked before <code>await theTask</code> - await keyword throws TaskCancelledException at once. However, the dialog stays visible.</li>
  <li>If <code>await theTask;</code> is invoked before <code>IAsyncOperation.Cancel()</code>, the dialog stays visible, but unlike #1, <code>await</code> continues waiting for a button to be tapped. Only then a TaskCanceledException is raised. </li>
  </ol>
  
  <p>BTW, my scenario is #2: I need to be able to close message dialogs after some routine is already waiting for its completion.</p>