From ae074645d208fa6fccda379a509b486b2c60a9c3 Mon Sep 17 00:00:00 2001 From: "gu.martinm@gmail.com" Date: Sat, 16 Aug 2014 00:15:24 +0200 Subject: [PATCH] RemoteAgents WP8 Using ConfigureAwait(true) (it is the default value) just when I want to update the UI. --- WindowsPhone/RemoteAgents/RemoteAgents/MainPage.xaml.cs | 3 +++ WindowsPhone/RemoteAgents/RemoteAgents/View/View.cs | 6 ++++-- WindowsPhone/RemoteAgents/RemoteAgents/ViewModel/ViewModel.cs | 6 ++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/WindowsPhone/RemoteAgents/RemoteAgents/MainPage.xaml.cs b/WindowsPhone/RemoteAgents/RemoteAgents/MainPage.xaml.cs index 76c967c..bb16625 100644 --- a/WindowsPhone/RemoteAgents/RemoteAgents/MainPage.xaml.cs +++ b/WindowsPhone/RemoteAgents/RemoteAgents/MainPage.xaml.cs @@ -38,10 +38,12 @@ namespace RemoteAgents { try { + // Returning data in the same context (the UI thread) because we want to update the UI. this.CurrentDateTextBox.Text = await _view.GetCurrentDateAsync(); } catch (Exception exception) { + // TODO: Should I catch exceptions in the UI thread? I guess it is right but not sure... _logger.ErrorException("ButtonGetDateClicked error: ", exception); } } @@ -56,6 +58,7 @@ namespace RemoteAgents } catch (Exception exception) { + // TODO: Should I catch exceptions in the UI thread? I guess it is right but not sure... _logger.ErrorException("SendDataButtonClicked error: ", exception); } } diff --git a/WindowsPhone/RemoteAgents/RemoteAgents/View/View.cs b/WindowsPhone/RemoteAgents/RemoteAgents/View/View.cs index 29f225c..dc1bcb7 100644 --- a/WindowsPhone/RemoteAgents/RemoteAgents/View/View.cs +++ b/WindowsPhone/RemoteAgents/RemoteAgents/View/View.cs @@ -9,12 +9,14 @@ namespace RemoteAgents.WindowsPhone.View async public Task GetCurrentDateAsync() { - return await _vm.GetCurrentDateAsync(); + // Returning data in a diferent context. Upper layer decides. + return await _vm.GetCurrentDateAsync().ConfigureAwait(false); } async public Task SetWriteTextAsync(string text, int number) { - await _vm.SetWriteTextAsync(text, number); + // Returning data in a diferent context. Upper layer decides. + await _vm.SetWriteTextAsync(text, number).ConfigureAwait(false); } } } diff --git a/WindowsPhone/RemoteAgents/RemoteAgents/ViewModel/ViewModel.cs b/WindowsPhone/RemoteAgents/RemoteAgents/ViewModel/ViewModel.cs index 3320499..788a762 100644 --- a/WindowsPhone/RemoteAgents/RemoteAgents/ViewModel/ViewModel.cs +++ b/WindowsPhone/RemoteAgents/RemoteAgents/ViewModel/ViewModel.cs @@ -11,12 +11,14 @@ namespace RemoteAgents.WindowsPhone.ViewModel async public Task GetCurrentDateAsync() { - return await _remoteClient.PostRemoteServiceAsync(uri, "getCurrentDate"); + // Returning data in a diferent context. Upper layer decides. + return await _remoteClient.PostRemoteServiceAsync(uri, "getCurrentDate").ConfigureAwait(false); } async public Task SetWriteTextAsync(string text, int number) { - await _remoteClient.PostRemoteServiceAsync(uriSetWriteText, "setWriteText", text, number); + // Returning data in a diferent context. Upper layer decides. + await _remoteClient.PostRemoteServiceAsync(uriSetWriteText, "setWriteText", text, number).ConfigureAwait(false); } } -- 2.1.4