From 4185c3dbde4e621e6665cee1b5bafe4b0e55b06b Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 31 Jul 2015 22:13:58 +0100 Subject: [PATCH] Removed async update check due to threading issue --- Filtration.Tests/Services/TestHTTPService.cs | 4 ++-- Filtration/Services/HTTPService.cs | 7 +++---- Filtration/Services/UpdateCheckService.cs | 7 +++---- Filtration/ViewModels/MainWindowViewModel.cs | 11 +++++------ 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Filtration.Tests/Services/TestHTTPService.cs b/Filtration.Tests/Services/TestHTTPService.cs index 54b7665..5d8ec5d 100644 --- a/Filtration.Tests/Services/TestHTTPService.cs +++ b/Filtration.Tests/Services/TestHTTPService.cs @@ -8,13 +8,13 @@ namespace Filtration.Tests.Services public class TestHTTPService { [Test] - public async void GetContent_FetchesDataFromUrl() + public void GetContent_FetchesDataFromUrl() { // Arrange var service = new HTTPService(); // Act - var result = await service.GetContentAsync("http://ben-wallis.github.io/Filtration/filtration_version.xml"); + var result = service.GetContent("http://ben-wallis.github.io/Filtration/filtration_version.xml"); // Assert Assert.IsNotNull(result); diff --git a/Filtration/Services/HTTPService.cs b/Filtration/Services/HTTPService.cs index a9f728e..21492ad 100644 --- a/Filtration/Services/HTTPService.cs +++ b/Filtration/Services/HTTPService.cs @@ -1,24 +1,23 @@ using System; using System.IO; using System.Net; -using System.Threading.Tasks; namespace Filtration.Services { internal interface IHTTPService { - Task GetContentAsync(string url); + string GetContent(string url); } internal class HTTPService : IHTTPService { - public async Task GetContentAsync(string url) + public string GetContent(string url) { var urlUri = new Uri(url); var request = WebRequest.Create(urlUri); - var response = await request.GetResponseAsync(); + var response = request.GetResponse(); using (var s = response.GetResponseStream()) { using (var sr = new StreamReader(s)) diff --git a/Filtration/Services/UpdateCheckService.cs b/Filtration/Services/UpdateCheckService.cs index cb0c0ed..9ccb1dc 100644 --- a/Filtration/Services/UpdateCheckService.cs +++ b/Filtration/Services/UpdateCheckService.cs @@ -1,5 +1,4 @@ using System.IO; -using System.Threading.Tasks; using System.Xml.Serialization; using Filtration.Models; @@ -7,7 +6,7 @@ namespace Filtration.Services { internal interface IUpdateCheckService { - Task GetUpdateDataAsync(); + UpdateData GetUpdateData(); } internal class UpdateCheckService : IUpdateCheckService @@ -20,9 +19,9 @@ namespace Filtration.Services _httpService = httpService; } - public async Task GetUpdateDataAsync() + public UpdateData GetUpdateData() { - var updateXml = await _httpService.GetContentAsync(UpdateDataUrl); + var updateXml = _httpService.GetContent(UpdateDataUrl); return (DeserializeUpdateData(updateXml)); } diff --git a/Filtration/ViewModels/MainWindowViewModel.cs b/Filtration/ViewModels/MainWindowViewModel.cs index f059eae..4493667 100644 --- a/Filtration/ViewModels/MainWindowViewModel.cs +++ b/Filtration/ViewModels/MainWindowViewModel.cs @@ -4,12 +4,14 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; +using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Forms; using System.Windows.Forms.VisualStyles; using System.Windows.Media; using System.Windows.Media.Imaging; +using System.Windows.Threading; using Filtration.Common.Services; using Filtration.Common.ViewModels; using Filtration.Interface; @@ -191,10 +193,7 @@ namespace Filtration.ViewModels } }); - Task.Run(async () => - { - await CheckForUpdatesAsync(); - }).Wait(); + CheckForUpdates(); } public RelayCommand OpenScriptCommand { get; private set; } @@ -238,13 +237,13 @@ namespace Filtration.ViewModels public RelayCommand ClearFiltersCommand { get; private set; } - public async Task CheckForUpdatesAsync() + public void CheckForUpdates() { var assemblyVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location); try { - var result = await _updateCheckService.GetUpdateDataAsync(); + var result = _updateCheckService.GetUpdateData(); if (result.LatestVersionMajorPart >= assemblyVersion.FileMajorPart && result.LatestVersionMinorPart > assemblyVersion.FileMinorPart)