clowd / Clowd.Squirrel

Quick and easy installer and automatic updates for cross-platform dotnet applications
426 stars 39 forks source link

Application freezes/loads forever on UpdateApp #86

Closed Lokyyn closed 2 years ago

Lokyyn commented 2 years ago

Hi, im using the UpdateApp()-Method of UpdateManager to check for updates, downloading and applying them at once. As soon as I am putting an "await" in front of that call the Application is taking for ever to make that call. However when im not using await it working as it should. My files are on a Webserver. I do not know what I am doing wrong.

I am using the newest stable version.

caesay commented 2 years ago

This sounds like a typical await deadlock, although I am unsure what is causing this. Could you please share more about your app? Is it WPF? what framework version?

You could try adding ConfigureAwait to your call, eg. var newVersion = await um.UpdateApp().ConfigureAwait(false).

Lokyyn commented 2 years ago

I tested your suggestion and It seams that it solved the problem, that my application freezes. My UI is still not reponsive for the whole time the UpdateManager checks, downloads and applies the update.

caesay commented 2 years ago

If your application is still unresponsive after adding ConfigureAwait, then the problem does not exist within Squirrel - but somewhere else inside your application.

In the following example, even though UpdateManager.UpdateApp has been awaited, in the OnClick handler, there is a blocking call to task.Result. This will cause your app to freeze and become unresponsive.

private Task<ReleaseEntry> UpdateMyApp() {
    using var um = new UpdateManager(...);
    return await um.UpdateApp();
}

private void OnUpdateButtonClick(object sender, EventArgs e) {
    var newVer = UpdateMyApp().Result; // <-- this is bad. don't do this!
    if (newVer != null) MessageBox.Show("An update has been installed!");
}

Please review the entire callstack where your update function has been executed, ensuring there are no blocking calls such as task.Result, task.Wait, task.GetResult() etc. If you are still having problems, please post a repository to GitHub which reproduces the problem and I will investigate further.