Refactor update check

This commit is contained in:
2018-02-22 20:55:42 -05:00
parent 15a1ae0e36
commit 8f550463b7

View File

@@ -29,10 +29,18 @@ namespace ProcessCpuUsageStatusWindow
_processCpuUsageWatcher = new ProcessCpuUsageWatcher();
Task.Factory.StartNew(UpdateApp);
Task.Factory.StartNew(UpdateApp).ContinueWith(task => StartUpdate(task.Result.Result));
}
private async Task UpdateApp()
private void StartUpdate(bool updateRequired)
{
if (updateRequired)
return;
Task.Factory.StartNew(() => _processCpuUsageWatcher.Initialize(Settings.Default.UpdateInterval, UpdateDisplay, _dispatcher));
}
private async Task<bool> UpdateApp()
{
try
{
@@ -45,7 +53,7 @@ namespace ProcessCpuUsageStatusWindow
var lastVersion = updates?.ReleasesToApply?.OrderBy(releaseEntry => releaseEntry.Version).LastOrDefault();
if (lastVersion == null)
return;
return false;
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.Updating));
Thread.Sleep(500);
@@ -60,16 +68,18 @@ namespace ProcessCpuUsageStatusWindow
}
#if !DEBUG
_dispatcher.Invoke(Dispose);
UpdateManager.RestartApp();
#endif
return true;
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
finally
{
await Task.Factory.StartNew(() => _processCpuUsageWatcher.Initialize(Settings.Default.UpdateInterval, UpdateDisplay, _dispatcher));
return false;
}
}