I’ve got a ClickOnce application which I need to update.
Running ApplicationDeployment.CurrentDeployment.CheckfForDetailedUpdate() returns details that there is an update available from the server and it gets the correct version number of the application on the server.
When I run the UpdateAsync method, nothing happens and the program hangs in the infinite while loop as shown in the code.
What could be wrong?
Here’s the code
if (ApplicationDeployment.IsNetworkDeployed)
if (ApplicationDeployment.CurrentDeployment.CheckForUpdate())
{
long downloaded = 0;
bool write = false;
bool updateCompleted = false;
deployment.UpdateCompleted += (sender, e) => updateCompleted = true;
deployment.UpdateProgressChanged += (sender, e) =>
{
//used to write to the log file the first time anything downloads
if (downloaded == 0)
write = true;
downloaded = e.BytesCompleted;
};
deployment.UpdateAsync();
//suspend while updating
while (!updateCompleted)
{
//write is never true implying that nothing gets downloaded
if (write)
{
log.Info(
"Downloaded " + downloaded + " bytes of " + total + ".");
write = false;
}
Thread.Sleep(10);
}
}
My guess would be that you’re blocking the main application thread in the while loop and the
UpdateCompletedis waiting for your main application thread to become idle so that it can run. This guess is supported by MSDN documentation that states that: