diff --git a/Samples/SampleWdpClient.UniversalWindows/MainPage.xaml.cs b/Samples/SampleWdpClient.UniversalWindows/MainPage.xaml.cs
index fca8e65a..ad8d8d3e 100644
--- a/Samples/SampleWdpClient.UniversalWindows/MainPage.xaml.cs
+++ b/Samples/SampleWdpClient.UniversalWindows/MainPage.xaml.cs
@@ -62,7 +62,7 @@ private void ClearOutput()
///
/// The caller of this method.
/// The arguments associated with this event.
- private void ConnectToDevice_Click(object sender, RoutedEventArgs e)
+ private async void ConnectToDevice_Click(object sender, RoutedEventArgs e)
{
this.EnableConnectionControls(false);
this.EnableDeviceControls(false);
@@ -78,61 +78,51 @@ private void ConnectToDevice_Click(object sender, RoutedEventArgs e)
this.password.Password));
StringBuilder sb = new StringBuilder();
- Task connectTask = new Task(
- async () =>
- {
- sb.Append(this.MarshalGetCommandOutput());
- sb.AppendLine("Connecting...");
- this.MarshalUpdateCommandOutput(sb.ToString());
- portal.ConnectionStatus += (portal, connectArgs) =>
- {
- if (connectArgs.Status == DeviceConnectionStatus.Connected)
- {
- sb.Append("Connected to: ");
- sb.AppendLine(portal.Address);
- sb.Append("OS version: ");
- sb.AppendLine(portal.OperatingSystemVersion);
- sb.Append("Device family: ");
- sb.AppendLine(portal.DeviceFamily);
- sb.Append("Platform: ");
- sb.AppendLine(String.Format("{0} ({1})",
- portal.PlatformName,
- portal.Platform.ToString()));
- }
- else if (connectArgs.Status == DeviceConnectionStatus.Failed)
- {
- sb.AppendLine("Failed to connect to the device.");
- sb.AppendLine(connectArgs.Message);
- }
- };
-
- try
- {
- // If the user wants to allow untrusted connections, make a call to GetRootDeviceCertificate
- // with acceptUntrustedCerts set to true. This will enable untrusted connections for the
- // remainder of this session.
- if (allowUntrusted)
- {
- this.certificate = await portal.GetRootDeviceCertificateAsync(true);
- }
- await portal.ConnectAsync(manualCertificate: this.certificate);
- }
- catch (Exception exception)
- {
- sb.AppendLine(exception.Message);
- }
- this.MarshalUpdateCommandOutput(sb.ToString());
- });
+ sb.Append(this.commandOutput.Text);
+ sb.AppendLine("Connecting...");
+ this.commandOutput.Text = sb.ToString();
+ portal.ConnectionStatus += (portal, connectArgs) =>
+ {
+ if (connectArgs.Status == DeviceConnectionStatus.Connected)
+ {
+ sb.Append("Connected to: ");
+ sb.AppendLine(portal.Address);
+ sb.Append("OS version: ");
+ sb.AppendLine(portal.OperatingSystemVersion);
+ sb.Append("Device family: ");
+ sb.AppendLine(portal.DeviceFamily);
+ sb.Append("Platform: ");
+ sb.AppendLine(String.Format("{0} ({1})",
+ portal.PlatformName,
+ portal.Platform.ToString()));
+ }
+ else if (connectArgs.Status == DeviceConnectionStatus.Failed)
+ {
+ sb.AppendLine("Failed to connect to the device.");
+ sb.AppendLine(connectArgs.Message);
+ }
+ };
- Task continuationTask = connectTask.ContinueWith(
- (t) =>
+ try
+ {
+ // If the user wants to allow untrusted connections, make a call to GetRootDeviceCertificate
+ // with acceptUntrustedCerts set to true. This will enable untrusted connections for the
+ // remainder of this session.
+ if (allowUntrusted)
{
- this.MarshalEnableDeviceControls(true);
- this.MarshalEnableConnectionControls(true);
- });
+ this.certificate = await portal.GetRootDeviceCertificateAsync(true);
+ }
+ await portal.ConnectAsync(manualCertificate: this.certificate);
+ }
+ catch (Exception exception)
+ {
+ sb.AppendLine(exception.Message);
+ }
- connectTask.Start();
+ this.commandOutput.Text = sb.ToString();
+ EnableDeviceControls(true);
+ EnableConnectionControls(true);
}
///
@@ -179,55 +169,45 @@ private void EnableDeviceControls(bool enable)
///
/// The caller of this method.
/// The arguments associated with this event.
- private void GetIPConfig_Click(object sender, RoutedEventArgs e)
+ private async void GetIPConfig_Click(object sender, RoutedEventArgs e)
{
this.ClearOutput();
this.EnableConnectionControls(false);
this.EnableDeviceControls(false);
StringBuilder sb = new StringBuilder();
- Task getTask = new Task(
- async () =>
- {
- sb.Append(this.MarshalGetCommandOutput());
- sb.AppendLine("Getting IP configuration...");
- this.MarshalUpdateCommandOutput(sb.ToString());
+ sb.Append(commandOutput.Text);
+ sb.AppendLine("Getting IP configuration...");
+ commandOutput.Text = sb.ToString();
- try
- {
- IpConfiguration ipconfig = await portal.GetIpConfigAsync();
-
- foreach (NetworkAdapterInfo adapterInfo in ipconfig.Adapters)
- {
- sb.Append(" ");
- sb.AppendLine(adapterInfo.Description);
- sb.Append(" MAC address :");
- sb.AppendLine(adapterInfo.MacAddress);
- foreach (IpAddressInfo address in adapterInfo.IpAddresses)
- {
- sb.Append(" IP address :");
- sb.AppendLine(address.Address);
- }
- sb.Append(" DHCP address :");
- sb.AppendLine(adapterInfo.Dhcp.Address.Address);
- }
- }
- catch (Exception ex)
- {
- sb.AppendLine("Failed to get IP config info.");
- sb.AppendLine(ex.GetType().ToString() + " - " + ex.Message);
- }
- });
+ try
+ {
+ IpConfiguration ipconfig = await portal.GetIpConfigAsync();
- Task continuationTask = getTask.ContinueWith(
- (t) =>
+ foreach (NetworkAdapterInfo adapterInfo in ipconfig.Adapters)
{
- this.MarshalUpdateCommandOutput(sb.ToString());
- this.MarshalEnableDeviceControls(true);
- this.MarshalEnableConnectionControls(true);
- });
+ sb.Append(" ");
+ sb.AppendLine(adapterInfo.Description);
+ sb.Append(" MAC address :");
+ sb.AppendLine(adapterInfo.MacAddress);
+ foreach (IpAddressInfo address in adapterInfo.IpAddresses)
+ {
+ sb.Append(" IP address :");
+ sb.AppendLine(address.Address);
+ }
+ sb.Append(" DHCP address :");
+ sb.AppendLine(adapterInfo.Dhcp.Address.Address);
+ }
+ }
+ catch (Exception ex)
+ {
+ sb.AppendLine("Failed to get IP config info.");
+ sb.AppendLine(ex.GetType().ToString() + " - " + ex.Message);
+ }
- getTask.Start();
+ commandOutput.Text = sb.ToString();
+ EnableDeviceControls(true);
+ EnableConnectionControls(true);
}
///
@@ -235,130 +215,57 @@ private void GetIPConfig_Click(object sender, RoutedEventArgs e)
///
/// The caller of this method.
/// The arguments associated with this event.
- private void GetWifiInfo_Click(object sender, RoutedEventArgs e)
+ private async void GetWifiInfo_Click(object sender, RoutedEventArgs e)
{
this.ClearOutput();
this.EnableConnectionControls(false);
this.EnableDeviceControls(false);
StringBuilder sb = new StringBuilder();
- Task getTask = new Task(
- async () =>
- {
- sb.Append(this.MarshalGetCommandOutput());
- sb.AppendLine("Getting WiFi interfaces and networks...");
- this.MarshalUpdateCommandOutput(sb.ToString());
-
- try
- {
- WifiInterfaces wifiInterfaces = await portal.GetWifiInterfacesAsync();
- sb.AppendLine("WiFi Interfaces:");
- foreach (WifiInterface wifiInterface in wifiInterfaces.Interfaces)
- {
- sb.Append(" ");
- sb.AppendLine(wifiInterface.Description);
- sb.Append(" GUID: ");
- sb.AppendLine(wifiInterface.Guid.ToString());
-
- WifiNetworks wifiNetworks = await portal.GetWifiNetworksAsync(wifiInterface.Guid);
- sb.AppendLine(" Networks:");
- foreach (WifiNetworkInfo network in wifiNetworks.AvailableNetworks)
- {
- sb.Append(" SSID: ");
- sb.AppendLine(network.Ssid);
- sb.Append(" Profile name: ");
- sb.AppendLine(network.ProfileName);
- sb.Append(" is connected: ");
- sb.AppendLine(network.IsConnected.ToString());
- sb.Append(" Channel: ");
- sb.AppendLine(network.Channel.ToString());
- sb.Append(" Authentication algorithm: ");
- sb.AppendLine(network.AuthenticationAlgorithm);
- sb.Append(" Signal quality: ");
- sb.AppendLine(network.SignalQuality.ToString());
- }
- };
- }
- catch (Exception ex)
- {
- sb.AppendLine("Failed to get WiFi info.");
- sb.AppendLine(ex.GetType().ToString() + " - " + ex.Message);
- }
- });
-
- Task continuationTask = getTask.ContinueWith(
- (t) =>
- {
- this.MarshalUpdateCommandOutput(sb.ToString());
- this.MarshalEnableDeviceControls(true);
- this.MarshalEnableConnectionControls(true);
- });
- getTask.Start();
- }
-
- ///
- /// Executes the EnabledConnectionControls method on the UI thread.
- ///
- /// True to enable the controls, false to disable them.
- private void MarshalEnableConnectionControls(bool enable)
- {
- Task t = this.Dispatcher.RunAsync(
- CoreDispatcherPriority.Normal,
- () =>
- {
- this.EnableConnectionControls(enable);
- }).AsTask();
- t.Wait();
- }
+ sb.Append(commandOutput.Text);
+ sb.AppendLine("Getting WiFi interfaces and networks...");
+ commandOutput.Text = sb.ToString();
- ///
- /// Executes the EnabledDeviceControls method on the UI thread.
- ///
- /// True to enable the controls, false to disable them.
- private void MarshalEnableDeviceControls(bool enable)
- {
- Task t = this.Dispatcher.RunAsync(
- CoreDispatcherPriority.Normal,
- () =>
- {
- this.EnableDeviceControls(enable);
- }).AsTask();
- t.Wait();
- }
-
- ///
- /// Executes the fetching of the text displayed in the command output UI element on the UI thread.
- ///
- /// The contents of the command output UI element.
- private string MarshalGetCommandOutput()
- {
- string output = string.Empty;
-
- Task t = this.Dispatcher.RunAsync(
- CoreDispatcherPriority.Normal,
- () =>
+ try
+ {
+ WifiInterfaces wifiInterfaces = await portal.GetWifiInterfacesAsync();
+ sb.AppendLine("WiFi Interfaces:");
+ foreach (WifiInterface wifiInterface in wifiInterfaces.Interfaces)
{
- output = this.commandOutput.Text;
- }).AsTask();
- t.Wait();
-
- return output;
- }
+ sb.Append(" ");
+ sb.AppendLine(wifiInterface.Description);
+ sb.Append(" GUID: ");
+ sb.AppendLine(wifiInterface.Guid.ToString());
+
+ WifiNetworks wifiNetworks = await portal.GetWifiNetworksAsync(wifiInterface.Guid);
+ sb.AppendLine(" Networks:");
+ foreach (WifiNetworkInfo network in wifiNetworks.AvailableNetworks)
+ {
+ sb.Append(" SSID: ");
+ sb.AppendLine(network.Ssid);
+ sb.Append(" Profile name: ");
+ sb.AppendLine(network.ProfileName);
+ sb.Append(" is connected: ");
+ sb.AppendLine(network.IsConnected.ToString());
+ sb.Append(" Channel: ");
+ sb.AppendLine(network.Channel.ToString());
+ sb.Append(" Authentication algorithm: ");
+ sb.AppendLine(network.AuthenticationAlgorithm);
+ sb.Append(" Signal quality: ");
+ sb.AppendLine(network.SignalQuality.ToString());
+ }
+ };
+ }
+ catch (Exception ex)
+ {
+ sb.AppendLine("Failed to get WiFi info.");
+ sb.AppendLine(ex.GetType().ToString() + " - " + ex.Message);
+ }
- ///
- /// Executes the update of the text displayed in the command output UI element ont he UI thread.
- ///
- /// The text to display in the command output UI element.
- private void MarshalUpdateCommandOutput(string output)
- {
- Task t = this.Dispatcher.RunAsync(
- CoreDispatcherPriority.Normal,
- () =>
- {
- this.commandOutput.Text = output;
- }).AsTask();
- t.Wait();
+ commandOutput.Text = sb.ToString();
+ EnableDeviceControls(true);
+ EnableConnectionControls(true);
}
///
@@ -376,7 +283,7 @@ private void Password_PasswordChanged(object sender, RoutedEventArgs e)
///
/// The caller of this method.
/// The arguments associated with this event.
- private void RebootDevice_Click(object sender, RoutedEventArgs e)
+ private async void RebootDevice_Click(object sender, RoutedEventArgs e)
{
bool reenableDeviceControls = false;
@@ -385,34 +292,25 @@ private void RebootDevice_Click(object sender, RoutedEventArgs e)
this.EnableDeviceControls(false);
StringBuilder sb = new StringBuilder();
- Task rebootTask = new Task(
- async () =>
- {
- sb.Append(this.MarshalGetCommandOutput());
- sb.AppendLine("Rebooting the device");
- this.MarshalUpdateCommandOutput(sb.ToString());
- try
- {
- await portal.RebootAsync();
- }
- catch (Exception ex)
- {
- sb.AppendLine("Failed to reboot the device.");
- sb.AppendLine(ex.GetType().ToString() + " - " + ex.Message);
- reenableDeviceControls = true;
- }
- });
+ sb.Append(commandOutput.Text);
+ sb.AppendLine("Rebooting the device");
+ commandOutput.Text = sb.ToString();
- Task continuationTask = rebootTask.ContinueWith(
- (t) =>
- {
- this.MarshalUpdateCommandOutput(sb.ToString());
- this.MarshalEnableDeviceControls(reenableDeviceControls);
- this.MarshalEnableConnectionControls(true);
- });
+ try
+ {
+ await portal.RebootAsync();
+ }
+ catch (Exception ex)
+ {
+ sb.AppendLine("Failed to reboot the device.");
+ sb.AppendLine(ex.GetType().ToString() + " - " + ex.Message);
+ reenableDeviceControls = true;
+ }
- rebootTask.Start();
+ commandOutput.Text = sb.ToString();
+ EnableDeviceControls(reenableDeviceControls);
+ EnableConnectionControls(true);
}
///
@@ -420,7 +318,7 @@ private void RebootDevice_Click(object sender, RoutedEventArgs e)
///
/// The caller of this method.
/// The arguments associated with this event.
- private void ShutdownDevice_Click(object sender, RoutedEventArgs e)
+ private async void ShutdownDevice_Click(object sender, RoutedEventArgs e)
{
bool reenableDeviceControls = false;
@@ -429,34 +327,23 @@ private void ShutdownDevice_Click(object sender, RoutedEventArgs e)
this.EnableDeviceControls(false);
StringBuilder sb = new StringBuilder();
- Task shutdownTask = new Task(
- async () =>
- {
- sb.Append(this.MarshalGetCommandOutput());
- sb.AppendLine("Shutting down the device");
- this.MarshalUpdateCommandOutput(sb.ToString());
-
- try
- {
- await portal.ShutdownAsync();
- }
- catch (Exception ex)
- {
- sb.AppendLine("Failed to shut down the device.");
- sb.AppendLine(ex.GetType().ToString() + " - " + ex.Message);
- reenableDeviceControls = true;
- }
- });
-
- Task continuationTask = shutdownTask.ContinueWith(
- (t) =>
- {
- this.MarshalUpdateCommandOutput(sb.ToString());
- this.MarshalEnableDeviceControls(reenableDeviceControls);
- this.MarshalEnableConnectionControls(true);
- });
+ sb.Append(commandOutput.Text);
+ sb.AppendLine("Shutting down the device");
+ commandOutput.Text = sb.ToString();
+ try
+ {
+ await portal.ShutdownAsync();
+ }
+ catch (Exception ex)
+ {
+ sb.AppendLine("Failed to shut down the device.");
+ sb.AppendLine(ex.GetType().ToString() + " - " + ex.Message);
+ reenableDeviceControls = true;
+ }
- shutdownTask.Start();
+ commandOutput.Text = sb.ToString();
+ EnableDeviceControls(reenableDeviceControls);
+ EnableConnectionControls(true);
}
///
diff --git a/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/RestDelete.cs b/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/RestDelete.cs
index 773180df..05019cda 100644
--- a/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/RestDelete.cs
+++ b/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/RestDelete.cs
@@ -43,7 +43,7 @@ private async Task DeleteAsync(Uri uri)
{
if (!response.IsSuccessStatusCode)
{
- throw new DevicePortalException(response);
+ throw await DevicePortalException.CreateAsync(response);
}
if (response.Content != null)
diff --git a/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/RestGet.cs b/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/RestGet.cs
index bca5ee88..c3e45d45 100644
--- a/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/RestGet.cs
+++ b/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/RestGet.cs
@@ -44,7 +44,7 @@ private async Task GetAsync(
{
if (!response.IsSuccessStatusCode)
{
- throw new DevicePortalException(response);
+ throw await DevicePortalException.CreateAsync(response);
}
using (HttpContent content = response.Content)
diff --git a/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/RestPost.cs b/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/RestPost.cs
index 6fa1755e..87423035 100644
--- a/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/RestPost.cs
+++ b/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/RestPost.cs
@@ -56,7 +56,7 @@ private async Task PostAsync(
{
if (!response.IsSuccessStatusCode)
{
- throw new DevicePortalException(response);
+ throw await DevicePortalException.CreateAsync(response);
}
if (response.Content != null)
diff --git a/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/RestPut.cs b/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/RestPut.cs
index d0f89aab..98c38a8d 100644
--- a/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/RestPut.cs
+++ b/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/RestPut.cs
@@ -47,7 +47,7 @@ private async Task PutAsync(
{
if (!response.IsSuccessStatusCode)
{
- throw new DevicePortalException(response);
+ throw await DevicePortalException.CreateAsync(response);
}
if (response.Content != null)
diff --git a/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/WebSocket.cs b/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/WebSocket.cs
index 2973898e..5439b300 100644
--- a/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/WebSocket.cs
+++ b/WindowsDevicePortalWrapper/UnitTestProject/WDPMockImplementations/WebSocket.cs
@@ -116,22 +116,19 @@ private async Task StartListeningForMessagesInternalAsync()
while (this.keepListeningForMessages)
{
await webSocketTask.ConfigureAwait(false);
- webSocketTask.Wait();
using (HttpResponseMessage response = webSocketTask.Result)
{
if (!response.IsSuccessStatusCode)
{
- throw new DevicePortalException(response);
+ throw await DevicePortalException.CreateAsync(response);
}
using (HttpContent content = response.Content)
{
MemoryStream dataStream = new MemoryStream();
- Task copyTask = content.CopyToAsync(dataStream);
- await copyTask.ConfigureAwait(false);
- copyTask.Wait();
+ await content.CopyToAsync(dataStream).ConfigureAwait(false);
// Ensure we return with the stream pointed at the origin.
dataStream.Position = 0;
@@ -165,7 +162,7 @@ private async Task SendMessageInternalAsync(string message)
{
if (!response.IsSuccessStatusCode)
{
- throw new DevicePortalException(response);
+ throw await DevicePortalException.CreateAsync(response);
}
}
}
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Core/AppDeployment.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Core/AppDeployment.cs
index 8dc87504..be904419 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Core/AppDeployment.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Core/AppDeployment.cs
@@ -185,7 +185,7 @@ public async Task InstallApplicationAsync(
await Task.Delay(TimeSpan.FromMilliseconds(stateCheckIntervalMs));
- status = await this.GetInstallStatusAsync();
+ status = await this.GetInstallStatusAsync().ConfigureAwait(false);
}
while (status == ApplicationInstallStatus.InProgress);
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Core/OsInformation.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Core/OsInformation.cs
index 0530bf9e..17771459 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Core/OsInformation.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Core/OsInformation.cs
@@ -93,7 +93,7 @@ public enum DevicePortalPlatforms
/// String containing the device's family.
public async Task GetDeviceFamilyAsync()
{
- DeviceOsFamily deviceFamily = await this.GetAsync(DeviceFamilyApi);
+ DeviceOsFamily deviceFamily = await this.GetAsync(DeviceFamilyApi).ConfigureAwait(false);
return deviceFamily.Family;
}
@@ -111,9 +111,9 @@ public async Task GetDeviceNameAsync()
/// Gets information about the device's operating system.
///
/// OperatingSystemInformation object containing details of the installed operating system.
- public async Task GetOperatingSystemInformationAsync()
+ public Task GetOperatingSystemInformationAsync()
{
- return await this.GetAsync(OsInfoApi);
+ return this.GetAsync(OsInfoApi);
}
///
@@ -122,9 +122,9 @@ public async Task GetOperatingSystemInformationAsync
/// The name to assign to the device.
/// The new name does not take effect until the device has been restarted.
/// Task tracking setting the device name completion.
- public async Task SetDeviceNameAsync(string name)
+ public Task SetDeviceNameAsync(string name)
{
- await this.PostAsync(
+ return this.PostAsync(
MachineNameApi,
string.Format("name={0}", Utilities.Hex64Encode(name)));
}
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/DevicePortal.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/DevicePortal.cs
index bff970db..ed6278c7 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/DevicePortal.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/DevicePortal.cs
@@ -216,8 +216,8 @@ public async Task ConnectAsync(
DeviceConnectionStatus.Connecting,
DeviceConnectionPhase.RequestingOperatingSystemInformation,
connectionPhaseDescription);
- this.deviceConnection.Family = await this.GetDeviceFamilyAsync();
- this.deviceConnection.OsInfo = await this.GetOperatingSystemInformationAsync();
+ this.deviceConnection.Family = await this.GetDeviceFamilyAsync().ConfigureAwait(false);
+ this.deviceConnection.OsInfo = await this.GetOperatingSystemInformationAsync().ConfigureAwait(false);
// Default to using whatever was specified in the connection.
bool requiresHttps = this.IsUsingHttps();
@@ -231,7 +231,7 @@ public async Task ConnectAsync(
DeviceConnectionStatus.Connecting,
DeviceConnectionPhase.DeterminingConnectionRequirements,
connectionPhaseDescription);
- requiresHttps = await this.GetIsHttpsRequiredAsync();
+ requiresHttps = await this.GetIsHttpsRequiredAsync().ConfigureAwait(false);
}
// Connect the device to the specified network.
@@ -242,10 +242,10 @@ public async Task ConnectAsync(
DeviceConnectionStatus.Connecting,
DeviceConnectionPhase.ConnectingToTargetNetwork,
connectionPhaseDescription);
- WifiInterfaces wifiInterfaces = await this.GetWifiInterfacesAsync();
+ WifiInterfaces wifiInterfaces = await this.GetWifiInterfacesAsync().ConfigureAwait(false);
// TODO - consider what to do if there is more than one wifi interface on a device
- await this.ConnectToWifiNetworkAsync(wifiInterfaces.Interfaces[0].Guid, ssid, ssidKey);
+ await this.ConnectToWifiNetworkAsync(wifiInterfaces.Interfaces[0].Guid, ssid, ssidKey).ConfigureAwait(false);
}
// Get the device's IP configuration and update the connection as appropriate.
@@ -268,7 +268,7 @@ public async Task ConnectAsync(
}
this.deviceConnection.UpdateConnection(
- await this.GetIpConfigAsync(),
+ await this.GetIpConfigAsync().ConfigureAwait(false),
requiresHttps,
preservePort);
}
@@ -296,6 +296,7 @@ await this.GetIpConfigAsync(),
while (innermostException.InnerException != null)
{
innermostException = innermostException.InnerException;
+ await Task.Yield();
}
this.ConnectionFailedDescription = innermostException.Message;
@@ -372,16 +373,13 @@ public async Task SaveEndpointResponseToFileAsync(
websocket.WebSocketStreamReceived += streamReceivedHandler;
- Task connect = websocket.ConnectAsync(endpoint);
- connect.Wait();
+ await websocket.ConnectAsync(endpoint);
- Task startListeningForStreamTask = websocket.ReceiveMessagesAsync();
- startListeningForStreamTask.Wait();
+ await websocket.ReceiveMessagesAsync();
streamReceived.WaitOne();
- Task stopListeningForStreamTask = websocket.CloseAsync();
- stopListeningForStreamTask.Wait();
+ await websocket.CloseAsync();
websocket.WebSocketStreamReceived -= streamReceivedHandler;
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Exceptions/DevicePortalException.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Exceptions/DevicePortalException.cs
index 6abfd68a..6fb6f5c7 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Exceptions/DevicePortalException.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Exceptions/DevicePortalException.cs
@@ -72,16 +72,16 @@ public DevicePortalException(
/// Http response message.
/// Optional exception message.
/// Optional inner exception.
- public DevicePortalException(
+ public static async Task CreateAsync(
HttpResponseMessage responseMessage,
string message = "",
- Exception innerException = null) : this(
- responseMessage.StatusCode,
+ Exception innerException = null)
+ {
+ DevicePortalException error = new DevicePortalException(responseMessage.StatusCode,
responseMessage.ReasonPhrase,
responseMessage.RequestMessage != null ? responseMessage.RequestMessage.RequestUri : null,
message,
- innerException)
- {
+ innerException);
try
{
if (responseMessage.Content != null)
@@ -92,9 +92,7 @@ public DevicePortalException(
{
dataStream = new MemoryStream();
- Task copyTask = content.CopyToAsync(dataStream);
- copyTask.ConfigureAwait(false);
- copyTask.Wait();
+ await content.CopyToAsync(dataStream).ConfigureAwait(false);
// Ensure we point the stream at the origin.
dataStream.Position = 0;
@@ -103,12 +101,7 @@ public DevicePortalException(
IBuffer dataBuffer = null;
using (IHttpContent messageContent = responseMessage.Content)
{
- IAsyncOperationWithProgress bufferOperation = messageContent.ReadAsBufferAsync();
- while (bufferOperation.Status != AsyncStatus.Completed)
- {
- }
-
- dataBuffer = bufferOperation.GetResults();
+ dataBuffer = await messageContent.ReadAsBufferAsync();
if (dataBuffer != null)
{
@@ -123,19 +116,21 @@ public DevicePortalException(
HttpErrorResponse errorResponse = (HttpErrorResponse)serializer.ReadObject(dataStream);
- this.HResult = errorResponse.ErrorCode;
- this.Reason = errorResponse.ErrorMessage;
+ error.HResult = errorResponse.ErrorCode;
+ error.Reason = errorResponse.ErrorMessage;
// If we didn't get the Hresult and reason from these properties, try the other ones.
- if (this.HResult == 0)
+ if (error.HResult == 0)
{
- this.HResult = errorResponse.Code;
+ error.HResult = errorResponse.Code;
}
- if (string.IsNullOrEmpty(this.Reason))
+ if (string.IsNullOrEmpty(error.Reason))
{
- this.Reason = errorResponse.Reason;
+ error.Reason = errorResponse.Reason;
}
+
+ dataStream.Dispose();
}
}
}
@@ -143,6 +138,7 @@ public DevicePortalException(
{
// Do nothing if we fail to get additional error details from the response body.
}
+ return error;
}
///
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/HttpRest/RestGet.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/HttpRest/RestGet.cs
index 0a027444..8f5b4c31 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/HttpRest/RestGet.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/HttpRest/RestGet.cs
@@ -83,7 +83,7 @@ private async Task GetAsync(
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
- using (Stream dataStream = await this.GetAsync(uri))
+ using (Stream dataStream = await this.GetAsync(uri).ConfigureAwait(false))
{
if ((dataStream != null) &&
(dataStream.Length != 0))
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/IoT/BluetoothConnectivity.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/IoT/BluetoothConnectivity.cs
index 7e15254b..7a27ba55 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/IoT/BluetoothConnectivity.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/IoT/BluetoothConnectivity.cs
@@ -72,7 +72,7 @@ public partial class DevicePortal
/// Gets the available bluetooth device information.
///
/// List of Available bluetooth devices
- public AvailableBluetoothDevicesInfo GetAvailableBluetoothDevicesInfo()
+ public async Task GetAvailableBluetoothDevicesInfoAsync()
{
AvailableBluetoothDevicesInfo bluetooth = null;
ManualResetEvent bluetoothReceived = new ManualResetEvent(false);
@@ -87,13 +87,11 @@ public AvailableBluetoothDevicesInfo GetAvailableBluetoothDevicesInfo()
};
this.BluetoothDeviceListReceived += bluetoothReceivedHandler;
- Task startListeningForBluetooth = this.StartListeningForBluetoothAsync(AvailableBluetoothDevicesApi);
- startListeningForBluetooth.Wait();
+ await this.StartListeningForBluetoothAsync(AvailableBluetoothDevicesApi);
bluetoothReceived.WaitOne();
- Task stopListeningForBluetooth = this.StopListeningForBluetoothAsync();
- stopListeningForBluetooth.Wait();
+ await this.StopListeningForBluetoothAsync();
this.BluetoothDeviceListReceived -= bluetoothReceivedHandler;
return bluetooth;
@@ -103,7 +101,7 @@ public AvailableBluetoothDevicesInfo GetAvailableBluetoothDevicesInfo()
/// Gets the paired bluetooth device information.
///
/// List of paired bluetooth devices
- public PairedBluetoothDevicesInfo GetPairedBluetoothDevicesInfo()
+ public async Task GetPairedBluetoothDevicesInfoAsync()
{
PairedBluetoothDevicesInfo bluetooth = null;
ManualResetEvent pairedBluetoothReceived = new ManualResetEvent(false);
@@ -118,13 +116,11 @@ public PairedBluetoothDevicesInfo GetPairedBluetoothDevicesInfo()
};
this.PairedBluetoothDeviceListReceived += pairedBluetoothReceivedHandler;
- Task startListeningForPairedBluetooth = this.StartListeningForPairedBluetoothAsync(PairedBluetoothDevicesApi);
- startListeningForPairedBluetooth.Wait();
+ await this.StartListeningForPairedBluetoothAsync(PairedBluetoothDevicesApi);
pairedBluetoothReceived.WaitOne();
- Task stopListeningForPairedBluetooth = this.StopListeningForPairedBluetoothAsync();
- stopListeningForPairedBluetooth.Wait();
+ await this.StopListeningForPairedBluetoothAsync();
this.PairedBluetoothDeviceListReceived -= pairedBluetoothReceivedHandler;
return bluetooth;
@@ -135,7 +131,7 @@ public PairedBluetoothDevicesInfo GetPairedBluetoothDevicesInfo()
///
/// Device Id.
/// Results of pairing a bluetooth device
- public PairBluetoothDevicesInfo GetPairBluetoothDevicesInfo(string deviceId)
+ public async Task GetPairBluetoothDevicesInfoAsync(string deviceId)
{
PairBluetoothDevicesInfo bluetooth = null;
ManualResetEvent pairBluetoothReceived = new ManualResetEvent(false);
@@ -150,13 +146,11 @@ public PairBluetoothDevicesInfo GetPairBluetoothDevicesInfo(string deviceId)
};
this.PairBluetoothDeviceListReceived += pairBluetoothReceivedHandler;
- Task startListeningForPairBluetooth = this.StartListeningForPairBluetoothAsync(PairBluetoothDevicesApi, string.Format("deviceId={0}", Utilities.Hex64Encode(deviceId)));
- startListeningForPairBluetooth.Wait();
+ await this.StartListeningForPairBluetoothAsync(PairBluetoothDevicesApi, string.Format("deviceId={0}", Utilities.Hex64Encode(deviceId)));
pairBluetoothReceived.WaitOne();
- Task stopListeningForPairBluetooth = this.StopListeningForPairBluetoothAsync();
- stopListeningForPairBluetooth.Wait();
+ await this.StopListeningForPairBluetoothAsync();
this.PairBluetoothDeviceListReceived -= pairBluetoothReceivedHandler;
return bluetooth;
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Xbox/XboxAppDeployment.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Xbox/XboxAppDeployment.cs
index 923f4381..074e9b51 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Xbox/XboxAppDeployment.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Xbox/XboxAppDeployment.cs
@@ -40,15 +40,15 @@ public async Task RegisterApplicationAsync(string folderName)
await this.PostAsync(
RegisterPackageApi,
- string.Format("folder={0}", Utilities.Hex64Encode(folderName)));
+ string.Format("folder={0}", Utilities.Hex64Encode(folderName))).ConfigureAwait(false);
// Poll the status until complete.
ApplicationInstallStatus status = ApplicationInstallStatus.InProgress;
do
{
- await Task.Delay(TimeSpan.FromMilliseconds(500));
+ await Task.Delay(TimeSpan.FromMilliseconds(500)).ConfigureAwait(false);
- status = await this.GetInstallStatusAsync();
+ status = await this.GetInstallStatusAsync().ConfigureAwait(false);
}
while (status == ApplicationInstallStatus.InProgress);
}
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/CertificateHandling.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/CertificateHandling.cs
index 35a6261f..5c140920 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/CertificateHandling.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/CertificateHandling.cs
@@ -43,24 +43,11 @@ public async Task GetRootDeviceCertificateAsync(bool acceptUntruste
using (HttpClient client = new HttpClient(requestSettings))
{
this.ApplyHttpHeaders(client, HttpMethods.Get);
-
- IAsyncOperationWithProgress responseOperation = client.GetAsync(uri);
- TaskAwaiter responseAwaiter = responseOperation.GetAwaiter();
- while (!responseAwaiter.IsCompleted)
- {
- }
-
- using (HttpResponseMessage response = responseOperation.GetResults())
+ using (HttpResponseMessage response = await client.GetAsync(uri))
{
using (IHttpContent messageContent = response.Content)
{
- IAsyncOperationWithProgress bufferOperation = messageContent.ReadAsBufferAsync();
- TaskAwaiter readBufferAwaiter = bufferOperation.GetAwaiter();
- while (!readBufferAwaiter.IsCompleted)
- {
- }
-
- certificate = new Certificate(bufferOperation.GetResults());
+ certificate = new Certificate(await messageContent.ReadAsBufferAsync());
}
}
}
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/Core/AppDeployment.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/Core/AppDeployment.cs
index 61328091..f8959235 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/Core/AppDeployment.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/Core/AppDeployment.cs
@@ -53,12 +53,7 @@ public async Task GetInstallStatusAsync()
{
this.ApplyHttpHeaders(client, HttpMethods.Get);
- IAsyncOperationWithProgress responseOperation = client.GetAsync(uri);
- while (responseOperation.Status != AsyncStatus.Completed)
- {
- }
-
- using (HttpResponseMessage response = responseOperation.GetResults())
+ using (HttpResponseMessage response = await client.GetAsync(uri))
{
if (response.IsSuccessStatusCode)
{
@@ -72,12 +67,7 @@ public async Task GetInstallStatusAsync()
IBuffer dataBuffer = null;
using (IHttpContent messageContent = response.Content)
{
- IAsyncOperationWithProgress bufferOperation = messageContent.ReadAsBufferAsync();
- while (bufferOperation.Status != AsyncStatus.Completed)
- {
- }
-
- dataBuffer = bufferOperation.GetResults();
+ dataBuffer = await messageContent.ReadAsBufferAsync();
if (dataBuffer != null)
{
@@ -114,7 +104,7 @@ public async Task GetInstallStatusAsync()
}
else
{
- throw new DevicePortalException(response);
+ throw await DevicePortalException.CreateAsync(response);
}
}
}
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestDelete.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestDelete.cs
index ed8aa767..8ae60a44 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestDelete.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestDelete.cs
@@ -45,30 +45,18 @@ private async Task DeleteAsync(Uri uri)
using (HttpClient client = new HttpClient(httpFilter))
{
this.ApplyHttpHeaders(client, HttpMethods.Delete);
-
- IAsyncOperationWithProgress responseOperation = client.DeleteAsync(uri);
- TaskAwaiter responseAwaiter = responseOperation.GetAwaiter();
- while (!responseAwaiter.IsCompleted)
- {
- }
-
- using (HttpResponseMessage response = responseOperation.GetResults())
+ using (HttpResponseMessage response = await client.DeleteAsync(uri))
{
if (!response.IsSuccessStatusCode)
{
- throw new DevicePortalException(response);
+ throw await DevicePortalException.CreateAsync(response);
}
if (response.Content != null)
{
using (IHttpContent messageContent = response.Content)
{
- IAsyncOperationWithProgress bufferOperation = messageContent.ReadAsBufferAsync();
- while (bufferOperation.Status != AsyncStatus.Completed)
- {
- }
-
- dataBuffer = bufferOperation.GetResults();
+ dataBuffer = await messageContent.ReadAsBufferAsync();
}
}
}
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestGet.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestGet.cs
index 38593c45..10e3952b 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestGet.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestGet.cs
@@ -45,28 +45,16 @@ private async Task GetAsync(Uri uri)
using (HttpClient client = new HttpClient(requestSettings))
{
this.ApplyHttpHeaders(client, HttpMethods.Get);
-
- IAsyncOperationWithProgress responseOperation = client.GetAsync(uri);
- TaskAwaiter responseAwaiter = responseOperation.GetAwaiter();
- while (!responseAwaiter.IsCompleted)
- {
- }
-
- using (HttpResponseMessage response = responseOperation.GetResults())
+ using (HttpResponseMessage response = await client.GetAsync(uri))
{
if (!response.IsSuccessStatusCode)
{
- throw new DevicePortalException(response);
+ throw await DevicePortalException.CreateAsync(response);
}
using (IHttpContent messageContent = response.Content)
{
- IAsyncOperationWithProgress bufferOperation = messageContent.ReadAsBufferAsync();
- while (bufferOperation.Status != AsyncStatus.Completed)
- {
- }
-
- dataBuffer = bufferOperation.GetResults();
+ dataBuffer = await messageContent.ReadAsBufferAsync();
}
}
}
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestPost.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestPost.cs
index 3a634322..b8eabb84 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestPost.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestPost.cs
@@ -58,30 +58,18 @@ private async Task PostAsync(
using (HttpClient client = new HttpClient(httpFilter))
{
this.ApplyHttpHeaders(client, HttpMethods.Post);
-
- IAsyncOperationWithProgress responseOperation = client.PostAsync(uri, requestContent);
- TaskAwaiter responseAwaiter = responseOperation.GetAwaiter();
- while (!responseAwaiter.IsCompleted)
- {
- }
-
- using (HttpResponseMessage response = responseOperation.GetResults())
+ using (HttpResponseMessage response = await client.PostAsync(uri, requestContent))
{
if (!response.IsSuccessStatusCode)
{
- throw new DevicePortalException(response);
+ throw await DevicePortalException.CreateAsync(response);
}
if (response.Content != null)
{
using (IHttpContent messageContent = response.Content)
{
- IAsyncOperationWithProgress bufferOperation = messageContent.ReadAsBufferAsync();
- while (bufferOperation.Status != AsyncStatus.Completed)
- {
- }
-
- dataBuffer = bufferOperation.GetResults();
+ dataBuffer = await messageContent.ReadAsBufferAsync();
}
}
}
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestPut.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestPut.cs
index 36548ec0..18661ab6 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestPut.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestPut.cs
@@ -50,29 +50,18 @@ private async Task PutAsync(
this.ApplyHttpHeaders(client, HttpMethods.Put);
// Send the request
- IAsyncOperationWithProgress responseOperation = client.PutAsync(uri, null);
- TaskAwaiter responseAwaiter = responseOperation.GetAwaiter();
- while (!responseAwaiter.IsCompleted)
- {
- }
-
- using (HttpResponseMessage response = responseOperation.GetResults())
+ using (HttpResponseMessage response = await client.PutAsync(uri, null))
{
if (!response.IsSuccessStatusCode)
{
- throw new DevicePortalException(response);
+ throw await DevicePortalException.CreateAsync(response);
}
if (response.Content != null)
{
using (IHttpContent messageContent = response.Content)
{
- IAsyncOperationWithProgress bufferOperation = messageContent.ReadAsBufferAsync();
- while (bufferOperation.Status != AsyncStatus.Completed)
- {
- }
-
- dataBuffer = bufferOperation.GetResults();
+ dataBuffer = await messageContent.ReadAsBufferAsync();
}
}
}
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/WebSocket.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/WebSocket.cs
index c1603bde..36e77b04 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/WebSocket.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/WebSocket.cs
@@ -113,7 +113,7 @@ await Task.Run(() =>
///
/// The that sent the message.
/// The message from the web socket.
- private void MessageReceived(MessageWebSocket sender, MessageWebSocketMessageReceivedEventArgs args)
+ private async void MessageReceived(MessageWebSocket sender, MessageWebSocketMessageReceivedEventArgs args)
{
if (this.IsListeningForMessages)
{
@@ -121,8 +121,7 @@ private void MessageReceived(MessageWebSocket sender, MessageWebSocketMessageRec
{
Stream stream = new MemoryStream();
- Task copyTask = inputStream.AsStreamForRead().CopyToAsync(stream);
- copyTask.Wait();
+ await inputStream.AsStreamForRead().CopyToAsync(stream);
// Ensure we return with the stream pointed at the origin.
stream.Position = 0;
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/Core/AppDeployment.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/Core/AppDeployment.cs
index 8457c36e..c410b35a 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/Core/AppDeployment.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/Core/AppDeployment.cs
@@ -39,12 +39,7 @@ public async Task GetInstallStatusAsync()
using (HttpClient client = new HttpClient(handler))
{
this.ApplyHttpHeaders(client, HttpMethods.Get);
-
- Task getTask = client.GetAsync(uri);
- await getTask.ConfigureAwait(false);
- getTask.Wait();
-
- using (HttpResponseMessage response = getTask.Result)
+ using (HttpResponseMessage response = await client.GetAsync(uri).ConfigureAwait(false))
{
if (response.IsSuccessStatusCode)
{
@@ -64,9 +59,7 @@ public async Task GetInstallStatusAsync()
{
dataStream = new MemoryStream();
- Task copyTask = content.CopyToAsync(dataStream);
- await copyTask.ConfigureAwait(false);
- copyTask.Wait();
+ await content.CopyToAsync(dataStream).ConfigureAwait(false);
// Ensure we point the stream at the origin.
dataStream.Position = 0;
@@ -101,7 +94,7 @@ public async Task GetInstallStatusAsync()
}
else
{
- throw new DevicePortalException(response);
+ throw await DevicePortalException.CreateAsync(response);
}
}
}
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/RestDelete.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/RestDelete.cs
index 29b87268..428c65c5 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/RestDelete.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/RestDelete.cs
@@ -35,15 +35,11 @@ private async Task DeleteAsync(Uri uri)
{
this.ApplyHttpHeaders(client, HttpMethods.Delete);
- Task deleteTask = client.DeleteAsync(uri);
- await deleteTask.ConfigureAwait(false);
- deleteTask.Wait();
-
- using (HttpResponseMessage response = deleteTask.Result)
+ using (HttpResponseMessage response = await client.DeleteAsync(uri).ConfigureAwait(false))
{
if (!response.IsSuccessStatusCode)
{
- throw new DevicePortalException(response);
+ throw await DevicePortalException.CreateAsync(response);
}
if (response.Content != null)
@@ -52,9 +48,7 @@ private async Task DeleteAsync(Uri uri)
{
dataStream = new MemoryStream();
- Task copyTask = content.CopyToAsync(dataStream);
- await copyTask.ConfigureAwait(false);
- copyTask.Wait();
+ await content.CopyToAsync(dataStream).ConfigureAwait(false);
// Ensure we return with the stream pointed at the origin.
dataStream.Position = 0;
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/RestGet.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/RestGet.cs
index 77f1dafa..e6c0d170 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/RestGet.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/RestGet.cs
@@ -35,24 +35,18 @@ private async Task GetAsync(
{
this.ApplyHttpHeaders(client, HttpMethods.Get);
- Task getTask = client.GetAsync(uri);
- await getTask.ConfigureAwait(false);
- getTask.Wait();
-
- using (HttpResponseMessage response = getTask.Result)
+ using (HttpResponseMessage response = await client.GetAsync(uri).ConfigureAwait(false))
{
if (!response.IsSuccessStatusCode)
{
- throw new DevicePortalException(response);
+ throw await DevicePortalException.CreateAsync(response);
}
using (HttpContent content = response.Content)
{
dataStream = new MemoryStream();
- Task copyTask = content.CopyToAsync(dataStream);
- await copyTask.ConfigureAwait(false);
- copyTask.Wait();
+ await content.CopyToAsync(dataStream).ConfigureAwait(false);
// Ensure we return with the stream pointed at the origin.
dataStream.Position = 0;
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/RestPost.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/RestPost.cs
index 898288c6..13f5a015 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/RestPost.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/RestPost.cs
@@ -48,15 +48,11 @@ private async Task PostAsync(
{
this.ApplyHttpHeaders(client, HttpMethods.Post);
- Task postTask = client.PostAsync(uri, requestContent);
- await postTask.ConfigureAwait(false);
- postTask.Wait();
-
- using (HttpResponseMessage response = postTask.Result)
+ using (HttpResponseMessage response = await client.PostAsync(uri, requestContent).ConfigureAwait(false))
{
if (!response.IsSuccessStatusCode)
{
- throw new DevicePortalException(response);
+ throw await DevicePortalException.CreateAsync(response);
}
if (response.Content != null)
@@ -65,9 +61,7 @@ private async Task PostAsync(
{
responseDataStream = new MemoryStream();
- Task copyTask = responseContent.CopyToAsync(responseDataStream);
- await copyTask.ConfigureAwait(false);
- copyTask.Wait();
+ await responseContent.CopyToAsync(responseDataStream).ConfigureAwait(false);
// Ensure we return with the stream pointed at the origin.
responseDataStream.Position = 0;
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/RestPut.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/RestPut.cs
index 4e9372a8..7097c753 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/RestPut.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/RestPut.cs
@@ -39,15 +39,11 @@ private async Task PutAsync(
this.ApplyHttpHeaders(client, HttpMethods.Put);
// Send the request
- Task putTask = client.PutAsync(uri, body);
- await putTask.ConfigureAwait(false);
- putTask.Wait();
-
- using (HttpResponseMessage response = putTask.Result)
+ using (HttpResponseMessage response = await client.PutAsync(uri, body).ConfigureAwait(false))
{
if (!response.IsSuccessStatusCode)
{
- throw new DevicePortalException(response);
+ throw await DevicePortalException.CreateAsync(response);
}
if (response.Content != null)
@@ -56,9 +52,7 @@ private async Task PutAsync(
{
dataStream = new MemoryStream();
- Task copyTask = content.CopyToAsync(dataStream);
- await copyTask.ConfigureAwait(false);
- copyTask.Wait();
+ await content.CopyToAsync(dataStream).ConfigureAwait(false);
// Ensure we return with the stream pointed at the origin.
dataStream.Position = 0;
diff --git a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/WebSocket.cs b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/WebSocket.cs
index ad844e32..14de4cd4 100644
--- a/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/WebSocket.cs
+++ b/WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/HttpRest/WebSocket.cs
@@ -150,7 +150,7 @@ private void StartListeningForMessagesInternal()
do
{
- result = await this.websocket.ReceiveAsync(buffer, CancellationToken.None);
+ result = await this.websocket.ReceiveAsync(buffer, CancellationToken.None).ConfigureAwait(false);
if (result.MessageType == WebSocketMessageType.Close)
{