mirror of
https://github.com/ckaczor/ProcessCpuUsageStatusWindow.git
synced 2026-01-13 17:23:02 -05:00
Refactor update check
This commit is contained in:
@@ -29,10 +29,18 @@ namespace ProcessCpuUsageStatusWindow
|
|||||||
|
|
||||||
_processCpuUsageWatcher = new ProcessCpuUsageWatcher();
|
_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
|
try
|
||||||
{
|
{
|
||||||
@@ -45,7 +53,7 @@ namespace ProcessCpuUsageStatusWindow
|
|||||||
var lastVersion = updates?.ReleasesToApply?.OrderBy(releaseEntry => releaseEntry.Version).LastOrDefault();
|
var lastVersion = updates?.ReleasesToApply?.OrderBy(releaseEntry => releaseEntry.Version).LastOrDefault();
|
||||||
|
|
||||||
if (lastVersion == null)
|
if (lastVersion == null)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.Updating));
|
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.Updating));
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(500);
|
||||||
@@ -60,16 +68,18 @@ namespace ProcessCpuUsageStatusWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
|
_dispatcher.Invoke(Dispose);
|
||||||
|
|
||||||
UpdateManager.RestartApp();
|
UpdateManager.RestartApp();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
Console.WriteLine(exception);
|
Console.WriteLine(exception);
|
||||||
}
|
|
||||||
finally
|
return false;
|
||||||
{
|
|
||||||
await Task.Factory.StartNew(() => _processCpuUsageWatcher.Initialize(Settings.Default.UpdateInterval, UpdateDisplay, _dispatcher));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +151,7 @@ namespace ProcessCpuUsageStatusWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateDisplay(Dictionary<string, ProcessCpuUsage> currentProcessList)
|
private void UpdateDisplay(Dictionary<string, ProcessCpuUsage> currentProcessList)
|
||||||
{
|
{
|
||||||
// Filter the process list to valid ones and exclude the idle and total values
|
// Filter the process list to valid ones and exclude the idle and total values
|
||||||
var validProcessList = (currentProcessList.Values.Where(
|
var validProcessList = (currentProcessList.Values.Where(
|
||||||
process =>
|
process =>
|
||||||
|
|||||||
Reference in New Issue
Block a user