From ff29b6e84f3475b4649a2f1715945e6d1080ff2c Mon Sep 17 00:00:00 2001 From: bao-qian Date: Sun, 5 Mar 2017 23:59:10 +0000 Subject: [PATCH] fix can't catch exception issue - Origin code can't catch exception in code, and all exceptions goes into first chance exception hanlding. - releated: #1266 - http://stackoverflow.com/a/5383408/2833083 - https://msdn.microsoft.com/en-us/magazine/jj991977.aspx?f=255&MSPPError=-2147217396 --- Wox.Core/Updater.cs | 7 ++----- Wox/App.xaml.cs | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Wox.Core/Updater.cs b/Wox.Core/Updater.cs index e5a97ea96e..9d3289ed60 100644 --- a/Wox.Core/Updater.cs +++ b/Wox.Core/Updater.cs @@ -14,8 +14,7 @@ namespace Wox.Core { public static class Updater { - [Conditional("RELEASE")] - public static async void UpdateApp() + public static async Task UpdateApp() { var client = new WebClient { Proxy = Http.WebProxy() }; @@ -24,9 +23,7 @@ namespace Wox.Core try { // todo 5/9 the return value of UpdateApp() is NULL, fucking useless! - using ( - var updater = - await UpdateManager.GitHubUpdateManager(Infrastructure.Constant.Github, urlDownloader: downloader)) + using (var updater = await UpdateManager.GitHubUpdateManager(Infrastructure.Constant.Github, urlDownloader: downloader)) { await updater.UpdateApp(); } diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index 6a12586d61..012f2be7e9 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Threading.Tasks; using System.Timers; using System.Windows; using Wox.Core; @@ -94,18 +95,25 @@ namespace Wox } } + [Conditional("RELEASE")] private void AutoUpdates() { - if (_settings.AutoUpdates) + Task.Run(async () => { - // check udpate every 5 hours - var timer = new Timer(1000 * 60 * 60 * 5); - timer.Elapsed += (s, e) => { Updater.UpdateApp(); }; - timer.Start(); + if (_settings.AutoUpdates) + { + // check udpate every 5 hours + var timer = new Timer(1000 * 60 * 60 * 5); + timer.Elapsed += async (s, e) => + { + await Updater.UpdateApp(); + }; + timer.Start(); - // check updates on startup - Updater.UpdateApp(); - } + // check updates on startup + await Updater.UpdateApp(); + } + }); } private void RegisterExitEvents()