title: How can I get a Silverlight application to check for an update and ask user to upgrade?
body: <p>I have made an out-of-browser <strong>silverlight</strong> application which I want to <strong>automatically update</strong> every time there is a <strong>new .xap file</strong> uploaded to the server.</p>
  
  <p>When the user right-clicks the application and clicks on <strong>Updates</strong>, the default is set to "<strong>Check for updates, but let me choose whether to download and install them</strong>":</p>
  
  <p><a href="https://i.stack.imgur.com/p1RCo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/p1RCo.png" alt="alt text"></a><br>
  <sub>(source: <a href="http://www.deviantsart.com/upload/uhjdal.png" rel="nofollow noreferrer">deviantsart.com</a>)</sub>  </p>
  
  <p>This leads me to believe that it is possible to make my Silverlight application automatically <strong>detect</strong> if there is a new .xap file present on the server, and if there is, the Silverlight client <strong>will automatically</strong> ask the user if he would like to install it.</p>
  
  <ul>
  <li><p>This however is not the case. I upload a new .xap file and the Silverlight application <strong>does nothing</strong>.</p></li>
  <li><p>Even if I add this to my <strong>App.xaml.cs</strong>:</p></li>
  </ul>
  
  <p>--</p>
  
  <pre><code>private void Application_Startup(object sender, StartupEventArgs e)
  {
      this.RootVisual = new BaseApp();
      if (Application.Current.IsRunningOutOfBrowser)
      {
          Application.Current.CheckAndDownloadUpdateAsync();
      }
  }
  </code></pre>
  
  <p>and update the .xap file, the Silverlight application <strong>does nothing</strong>.</p>
  
  <ul>
  <li><a href="https://docs.microsoft.com/en-us/previous-versions/windows/silverlight/dotnet-windows-silverlight/dd730310(v=vs.95)" rel="nofollow noreferrer">This information</a> enabled me to check if there is an update and if so, tell the user to restart the application, but when he restarts the application, <strong>nothing happens</strong>:</li>
  </ul>
  
  <p>--</p>
  
  <pre><code>private void Application_Startup(object sender, StartupEventArgs e)
  {
      this.RootVisual = new BaseApp();
      if (Application.Current.IsRunningOutOfBrowser)
      {
          Application.Current.CheckAndDownloadUpdateAsync();
          Application.Current.CheckAndDownloadUpdateCompleted += new CheckAndDownloadUpdateCompletedEventHandler(Current_CheckAndDownloadUpdateCompleted);
      }
  }
  
  void Current_CheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
  {
      if (e.UpdateAvailable)
      {
          MessageBox.Show("An application update has been downloaded. " +
              "Restart the application to run the new version.");
      }
      else if (e.Error != null &amp;&amp;
          e.Error is PlatformNotSupportedException)
      {
          MessageBox.Show("An application update is available, " +
              "but it requires a new version of Silverlight. " +
              "Visit the application home page to upgrade.");
      }
      else
      {
          //no new version available
      }
  }
  </code></pre>
  
  <p><strong>How do I make my Silverlight application check, each time it starts, if there is a new .xap file, and if there is, pass control to the Silverlight client to ask the user if he wants to download it, as the above dialogue implies is possible?</strong></p>