Once I've completed an update and the application has restarted, I'm getting an InvalidOperationException with 'Already checked for updates; to reset the current state call CleanUp()', which is getting called as part of the async BeginCheckForUpdates.
I'm using the following two methods on Window_Loaded() to configure NAppUpdate and check for updates:
/// <summary>
/// Initialises the NAppUpdate provider.
/// </summary>
void Updater_Init() {
// Grab the hostname from the config
var config = (ViewModels.ConfigViewModel)FindResource("ConfigViewModelDataSource");
var hostname = config.ServerHostname;
// Build the update source
var feedUrl = "http://" + hostname + "/RSS/WindowsClientUpdates";
var updateSource = new NAppUpdate.Framework.Sources.SimpleWebSource(feedUrl);
// Configure the update manager
var updateManager = UpdateManager.Instance;
updateManager.UpdateSource = updateSource;
updateManager.ReinstateIfRestarted();
}
/// <summary>
/// Checks for the updates.
/// </summary>
void Updater_CheckForUpdates() {
// Grab the instance
var updateManager = UpdateManager.Instance;
// Do an async update check
updateManager.BeginCheckForUpdates(asyncResult => {
Action updatesAvailable = Updater_UpdatesAvailable;
if (asyncResult.IsCompleted) {
// Throw any caught exceptions
((UpdateProcessAsyncResult)asyncResult).EndInvoke();
// If there's no updates, get out of here
if (updateManager.UpdatesAvailable == 0) {
return;
}
// If there are, mark we need to apply some.
applyUpdates = true;
// Call the updates available action
if (Dispatcher.CheckAccess()) {
updatesAvailable();
} else {
Dispatcher.Invoke(updatesAvailable);
}
}
}, null);
}
And the following to install the updates, which are being triggered manually via a WPF button press:
protected void UpdateNow(string sender) {
// Grab the update manager
var updateManager = UpdateManager.Instance;
// Begin the prepare
updateManager.BeginPrepareUpdates(asyncResult => {
((UpdateProcessAsyncResult)asyncResult).EndInvoke();
try {
updateManager.ApplyUpdates(true);
this.applyUpdates = false;
} catch {
MessageBox.Show("Could not install updates.");
}
updateManager.CleanUp();
}, null);
}
All seems fairly standard, and otherwise works well. It's pretty much copy and paste from the WPF sample application.
I know the exception implies it's already checked for updates, but I've added breakpoints at every method declaration, and none are being triggered multiple times. The call stack only shows up to the async method.
Suggestions?