"Already checked for updates; to reset the current state call CleanUp()" after update

226 views
Skip to first unread message

Matt Dwen

unread,
Apr 5, 2013, 11:10:54 PM4/5/13
to nappu...@googlegroups.com
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?

Itamar Syn-Hershko

unread,
Apr 6, 2013, 12:59:45 PM4/6/13
to nappu...@googlegroups.com
Can you add a breakpoint at Updater_CheckForUpdates before BeginCheckForUpdates , the first time its called after the app restarted, and check the current State recorded in UpdateManager?


--
You received this message because you are subscribed to the Google Groups "NAppUpdate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nappupdate+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Message has been deleted

Matt Dwen

unread,
Apr 6, 2013, 5:57:51 PM4/6/13
to nappu...@googlegroups.com
It get's hit once the first time the app runs. Then I install the update, it restarts, gets hit once again, then throws the InvalidOperationException.

If I run the initial execution by debugging in VS, then the application never automatically restarts, as I would expect. Though when I run it manually from /bin/debug after that first run, it knows it's just been updated, and crashes the same then too. I assume somewhere NAppUpdate is flagging that this is the first run after an update? And that I need to check for this somewhere and not check for updates again if it's in this state?

Itamar Syn-Hershko

unread,
Apr 10, 2013, 10:02:42 AM4/10/13
to nappu...@googlegroups.com
I suspect ReinstateIfRestarted forgets to reset the status - or I may have made this on purpose so you should call Cleanup() explicitly. Can you try calling Cleanup() after ReinstateIfRestarted()?


On Sun, Apr 7, 2013 at 12:56 AM, Matt Dwen <ma...@group6.co.nz> wrote:
It get's hit once the first time the app runs. Then I install the update, it restarts, gets hit once again, then throws the InvalidOperationException.

If I run the initial execution by debugging in VS, then the application never automatically restarts, as I would expect. Though when I run it manually from /bin/debug after that first run, it knows it's just been updated, and crashes the same then too. I assume somewhere NAppUpdate is flagging that this is the first run after an update? And that I need to check for this somewhere and not check for updates again if it's in this state?

--
You received this message because you are subscribed to a topic in the Google Groups "NAppUpdate" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nappupdate/7Zqus2NGuQ8/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to nappupdate+...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Matt Dwen
Group 6 Technologies
+64 21 486 281

Matt Dwen

unread,
Apr 10, 2013, 5:21:45 PM4/10/13
to nappu...@googlegroups.com
I've added a CleanUp() right after the ReinstateIfRestarted() and it seems happy.
Cheers :)
Reply all
Reply to author
Forward
0 new messages