Skip to content

Instantly share code, notes, and snippets.

@Ganeshcse
Created March 27, 2017 13:10
Show Gist options
  • Save Ganeshcse/585cc36e57068ac33fdc1fa0ff8dc30b to your computer and use it in GitHub Desktop.
Save Ganeshcse/585cc36e57068ac33fdc1fa0ff8dc30b to your computer and use it in GitHub Desktop.
/// <summary>
///
/// </summary>
/// <returns></returns>
private static void InstallUpdateSyncWithInfo()
{
try
{
if (ApplicationDeployment.IsNetworkDeployed)
{
var ad = ApplicationDeployment.CurrentDeployment;
UpdateCheckInfo info = null;
try
{
info = ad.CheckForDetailedUpdate();
}
catch (DeploymentDownloadException dde)
{
MessageBox.Show(
@"The new version of the application cannot be downloaded at this time. Please check your network connection, or try again later. Error: " +
dde.Message);
}
catch (InvalidDeploymentException ide)
{
MessageBox.Show(
@"Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " +
ide.Message);
}
catch (InvalidOperationException ioe)
{
MessageBox.Show(
@"This application cannot be updated. It is likely not a ClickOnce application. Error: " +
ioe.Message);
}
if (info.UpdateAvailable)
{
try
{
ad.Update();
Application.Restart();
}
catch (DeploymentDownloadException dde)
{
MessageBox.Show(
@"Cannot install the latest version of the application. Please check your network connection, or try again later. Error: " +
dde);
}
}
else
{
new MainWindow().Show();
}
}
else
{
MessageBox.Show(@"Not network deployed");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + @" " + ex.StackTrace);
}
}
/// <summary>
///
/// </summary>
/// <param name="e"></param>
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
InstallUpdateSyncWithInfo();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment