You probably have the "UpdateType" property set to "Automatic". This means, after an update is found it will begin downloading and installing the update. That is, you don't need to call InstallNow().
Tell me if this helps.
Hi,
I'm trying to programatically tell the AutomaticUpdater to check for updates, and then perform some other functions before finally telling the AutomaticUpdater to start the install process. I have an AutomaticUpdater control on my form (hidden) and I want to check on the load of the form if there are updates. I thought it would be as simple as the following
bool updateAvailable = automaticUpdater.ForceCheckForUpdate(); // Tried passing True and got the same result.
if (updateAvailable) { // Do stuff and prepare for update
automaticUpdater.InstallNow(); }
Whenever I run this code I get an error that says "the automaticupdater must finish checking for updates before they can be installed" or just recently, "The Update must finish extracting before you can install it". Is this a timing issue or something? I tried subscribing to the "UpdateAvailable" event and then ran InstallNow in that event, but I received the same errors. And what's weirder still is that sometimes the error will appear, but my app will update and restart. This makes me really think that it's a timing issue...hmmmm
It feels like I'm missing something obvious and I haven't been able to find it on the forums yet. Can anybody point me in the right direction? Many thanks!!!!
You probably have the "UpdateType" property set to "Automatic". This means, after an update is found it will begin downloading and installing the update. That is, you don't need to call InstallNow().
Tell me if this helps.
Hmmmm, ok. I changed my code to just force check for updates immediately on load. This does not work on the first load of the application, but if I close it (after waiting a bit) and then reopen it the update happens. On the first run, the ForceCheck returns True even. I think this is why I thought I needed the InstallNow() call after force checking. And you are right, I have the control set to "Automatic" (but I completely hide the control so there is no user interaction....if that matters) Any more thoughts? Thanks for helping!
Also, I checked the AutomaticUpdater to "CheckOnly" and revert back to the original posted code. I still get the same "Must finish checking for updates before installing" error. But then it sometimes ignores that and installs. Odd. 🙂
[EDIT] - Oops, I meant to say "DoNothing" for the UpdateType. But both "DoNothing" and "CheckOnly" result in the same error, but "CheckOnly" has the "sometimes ignore and installs" part.
Can you send me your code (or a simple example project that replicates the code you're using)? Send it to support@wyday.com. I'll take a look at it.
An email with a project has been sent. Thanks!
edit - (I forgot to send the client.wyc. Let me know if you need that at all and I'll send it as well. Thanks again!)
Hey Sam. Any update on this? 🙂
Yes, ForceCheckForUpdates() returns true if the checking has begun and false if the checking did not start. It's not a true or false of whether there are updates. For that ability use the AutomaticUpdater events, namely the UpdateAvailable event.
Hi again.
I tried implementing this way of updating, but I'm running into some similar problems. I'm hooking into the UpdateAvailable event and calling InstallNow there (if I'm understanding this correctly). When running wyUpdate by itself I it reports that there is an update. But the following code doesn't run. I did debug and I hit the MessageBox.Show. It wouldn't hit the InstallNow though. So I commented that out and it would hit the InstallUpdates, but not actually install. My AutomaticUpdater is set to "CheckOnly"
My code is currently this
private void automaticUpdater_UpdateAvailable(object sender, EventArgs e) { MessageBox.Show(this, "An update has been found. Click OK to update now.", "Update", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
automaticUpdater.InstallNow(); }
I also tried a delegate to Invoke and run InstallNow on the MainThread in case it was a threading issue and I have the same result. Is there just any way to run wyUpdate.exe silently? (my app runs under elevated privileges, so UAC shouldn't be an issue I hope.) Any other ideas? Thanks a ton!
I'm not quite sure why you want to reproduce the work that the AutomaticUpdater already does. Why don't you let the AutomaticUpdater handle all of the work for you?
So I commented that out and it would hit the InstallUpdates, but not actually install.
This is intended behavior. InstallNow() is (in retrospect) a poorly named function. Here's what it really does (more or less):
if (UpdateStepOn == UpdateStepOn.UpdateAvailable) { // begin downloading the update DownloadUpdate(); } else if (UpdateStepOn == UpdateStepOn.UpdateDownloaded) { ExtractUpdate(); } else // UpdateReadyToInstall { // begin installing the update InstallPendingUpdate(); }
So, with the UpdateType set to "CheckOnly" you'll likely be calling InstallNow() 3 times (once to download, once to extract, and once to install). Use the events UpdateAvailable and ReadyToBeInstalled along with the property "UpdateStepOn".
But this is way more work than you need to be doing. Why do you want to do this? The AutomaticUpdater was designed to be a simple "drop in" solution. You really don't need to re-implement everything that the AutomaticUpdater already does.
Well, when I put the AutomaticUpdater control on a form, it has always required the user to click "Install updates now" from what I have seen in testing. What I'm needing it to do is to install the updates without the user's consent on startup of the application. So Open -> update -> automatically restart for the user -> New Version. Is there a specific way to get the Control to do this? (if so, sorry for all the hassle! hahahaha)
Here's how the AutomaticUpdater works:
It periodically checks for updates. When updates are found, it downloads and extracts the update in the background when your app is running. Then, after your app is started by the user again, the AutomaticUpdater immediately closes your app, shows wyUpdate, and wyUpdate finishes the installation. Then the new version of your app is immediately started.
So to answer your question: your new update is installed on the next start of your app (after the update has already been downloaded and extracted).
It was purposefully designed to do most of the work in the background.
Hmmm, ok, I'm seeing this functionality. I had this actually working in the "once you restart the update will be applied" fashion before. I guess what I'm trying to do beyond that is to notify the user that there is an update and they need to restart, otherwise the current data the user will be using would be out of date and erroneous. Once I had the proper restart to update working, I tried to hook into the AutomaticUpdater's "UpdateAvailable" and give a message box prompt of something (maybe even restart the app for them), but no event is being fired here.
So, hopefully the last question (thank you for all of your help so far!). Do you have any suggestions on how to use the AutomaticUpdater to force an update on startup? Being whatever that might be. A force restart, message box to give the user a choice, whatever it takes to restart the app and apply the update whenever an update is found.
And just to have a little context. We have an application that is database replication driven, and we don't support any older versions at all. We force all the changes to happen so everybody has the same Database schema when syncing. So, keeping things up to date right on the start of the app is a bit crucial for us. And we release updates at night, when we know that nobody is using the application (because they use it during the day with their normal jobs so we're 100% sure that nobody uses it at night) Hopefully that adds a bit more clarity.
Thanks SO MUCH for your help! 🙂
With the UpdateType set to "Automatic", you can call the InstallNow() function in the "ReadyToBeInstalled" event -- this makes the assumption that they leave the app running during the night. If your users close the app at night, the next morning when they run your app, the installation will be invoked automatically by the AutomaticUpdater.
Thank you! That works wonderfully! Sorry that it took so long to get to this 🙂 You have a loyal customer now at least! ^_^ Thank you again!