Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > UpdateAsync() hanging
 

UpdateAsync() hanging

In using the example code from MSDN for programmatic update, my code gets to the async call, but fires no events.

I changed the async code for checking for an update to synchronous code and it works fine. But then the call to UpdateAsync() fires no events and downloads no bits, even though it knows that there is a new version. The synchronous Update() function works fine, though.

Naturally, I want async so that I can get the progress notifications and give my user a progress update during the download.

Some code... (splashScreen is a windows form that is open, non-modally, during startup.
updateCheckComplete is a boolean flag that I use to know that the async calls are complete. I call UpdateApplication() and then spin until updateCheckComplete is true.

Did I miss something?

private void UpdateApplication()
{
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

ad.UpdateCompleted += new AsyncCompletedEventHandler(ad_UpdateCompleted);
ad.UpdateProgressChanged += new DeploymentProgressChangedEventHandler(ad_UpdateProgressChanged);

if (ApplicationDeployment.IsNetworkDeployed)
{
UpdateCheckInfo uci;

try
{
uci = ad.CheckForDetailedUpdate();
}
catch (DeploymentDownloadException dde)
{
MessageBox.Show("The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " + dde.Message);

return;
}
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);

return;
}
catch (InvalidOperationException ioe)
{
MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message);

return;
}

// Ask the user if they would like to update the application now.

this.splashScreen.chkCheckingForUpdates.Checked = true;

if (uci.UpdateAvailable == true)
{
bool updateClear = false;

if (uci.IsUpdateRequired == false)
{
string version = uci.AvailableVersion.ToString(3) + " build " + uci.AvailableVersion.Revision.ToString();

DialogResult dr = MessageBox.Show("Version " + version + " of DropShark is now available. Would you like to update DropShark now?", "Update Available", MessageBoxButtons.OKCancel);

if (DialogResult.OK == dr)
{
updateClear = true;
}
else
{
this.updateCheckComplete = true;
}
}
else
{
MessageBox.Show("A mandatory update is available for DropShark. DropShark will now update and restart.");

updateClear = true;
}

if (updateClear == true)
{
MessageBox.Show("Going to do update");

this.splashScreen.lblProgress.Text = "Beginning update...";

this.splashScreen.Refresh();

ad.UpdateAsync();
}
}
else
{
this.updateCheckComplete = true;
}
}
else
{
this.updateCheckComplete = true;
}
}

void ad_UpdateCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.Cancelled)
{
MessageBox.Show("The update of the DropShark's latest version was cancelled.");

return;
}
else if (e.Error != null)
{
MessageBox.Show("ERROR: Could not install the latest version of DropShark. Reason: \n" + e.Error.Message + "\nPlease report this error to the system administrator.");

return;
}

this.splashScreen.chkCheckingForUpdates.Checked = true;

MessageBox.Show("Update complete! Click OK to Restart DropShark.");

Application.Restart();

this.updateCheckComplete = true;
}

void ad_UpdateProgressChanged(object sender, DeploymentProgressChangedEventArgs e)
{
String progressText = String.Format("{0:D}K out of {1:D}K downloaded - {2:D}% complete", e.BytesCompleted / 1024, e.BytesTotal / 1024, e.ProgressPercentage);

this.splashScreen.lblProgress.Text = progressText;

this.splashScreen.Refresh();
}

cambler  Monday, February 06, 2006 9:49 PM
Still waiting on this, Microsoft. I'm blocked. Sitting here reading the net with not much to do because I can't push this thing out for beta.

This is either a bug or it isn't, right? Has anyone else gotten UpdateAsync() to work?
cambler  Tuesday, February 07, 2006 8:30 PM
Another 24 hours, and no response.

1. Has anyone been able to get UpdateAsync() to work?

2. Microsoft, is this a known bug? Is there a workaround?

Anyone?
cambler  Wednesday, February 08, 2006 9:23 PM
Another day goes by without a word from MSFT on this issue...

Hey, Microsoft, I work in Bellevue. Whomever helps with this issue gets lunch at Kidd Valley on me.

I'm serious - even a response of, "yes, it's broken" will at least let me give up the issue and move on.

Hello?
cambler  Thursday, February 09, 2006 11:30 PM

Hi,sorry for the delayed response.

I copy-pasted your code into my sample ClickOnce application and it works just fine. UpdateAsync() downloads the new version of the application for me. I'm unable to repro the problem you're seeing.

Other thancommenting out the splashscreen code and replacing with message boxes I used your code as is. There aren't any known issues that would cause UpdateAsync() to hang completely, you really should be able to use it as you've described above.

Here are few possible things to check on:

- The one thing that would slow things down is if connection to server is down or slow, but then the sync version of the API should not have worked for you either. Can you confirm that both sync and async tests were done against some server.

- This is unlikely but theUpdateAsync() follows the regular .NET async programming model. I'm wondering if there's something wrong on your machine with async events in general. Can you try replacing UpdateAsync with another async method such as WebClient.DownloadFileAsync and see if that works for you in sample above.

- Comment out the splashscreen code on your end to see if that's causing a problem.

Let us know what you get and we can take it further from there.

Regards,
Sameer

Sameer Bhangar - MSFT  Friday, February 10, 2006 2:02 AM
Just a cursory comment. I had a problem with Aync calls blocking. It turns out that .NET has a few available background threads and will only do 2 async things at a time before blocking all further requests.

Sub OnLoad()
CallHomeToReportRunAsync() <--- async
GetListOfNewsItemsAsync() <--async
CheckForUpdateAsync() <--- BLOCKING
Msgbox("hi") <--- TAKES 10 SECONDS TO SHOW
End Sub

It's a flaw in the design of .NET

Perhaps this is what you are experiencing. perhaps not.
Display Name_2  Sunday, November 11, 2007 10:13 PM
I am using async updating and it seems to be working fine for me. I will compare my code with yours and if I see any differences I will post it here.

dbcuser  Monday, November 12, 2007 6:21 PM
Has anyone solved this problem yet as I have exactly the same problem.

I am not able to replicate the problem in a simple test application and I have tried to simulate the 2 async limit that Display Name_2 suggested but I was not able to replicate that either.

Does anyone have an idea how I go about debugging this problem?
John Hunter2  Friday, July 17, 2009 11:03 AM

You can use google to search for other answers

Custom Search

More Threads

• .NET UserControl/ActiveX upgrade problem.
• Weird error in setup
• Installer runs after reboot - VS2005
• ClickOnce not detecting new versions after Domain change
• Creating ClickOnce with Mage.exe removes 4 characters in .application
• ClickOnce Exception
• Deployment Issue - Modifying Config File dynamically by application users without Admin access
• WSUS Remote Storage error
• Upgrading version
• Deplyoment of the same XBAP from different origins to a single client