Skip to content

Commit d31bf49

Browse files
authored
Merge pull request #6229 from MicrosoftDocs/jdaly-main-ConfigureAwait
Removed ConfigureAwait from examples
2 parents 1f1f173 + e1983c2 commit d31bf49

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

powerapps-docs/developer/data-platform/application-insights-ilogger.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,13 @@ namespace ILoggerExample
168168
169169
HttpResponseMessage response = client
170170
.GetAsync(webAddress)
171-
.ConfigureAwait(false)
172171
.GetAwaiter()
173172
.GetResult(); //Make sure it is synchronous
174173
175174
response.EnsureSuccessStatusCode();
176175

177176
string responseText = response.Content
178177
.ReadAsStringAsync()
179-
.ConfigureAwait(false)
180178
.GetAwaiter()
181179
.GetResult(); //Make sure it is synchronous
182180

powerapps-docs/developer/data-platform/best-practices/business-logic/set-timeout-for-external-calls-from-plug-ins.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ using (HttpClient client = new HttpClient())
5656
client.DefaultRequestHeaders.ConnectionClose = true; //Set KeepAlive to false
5757
5858

59-
HttpResponseMessage response = client.GetAsync(webAddress).ConfigureAwait(false).GetAwaiter().GetResult(); //Make sure it is synchronous
59+
HttpResponseMessage response = client.GetAsync(webAddress).GetAwaiter().GetResult(); //Make sure it is synchronous
6060
response.EnsureSuccessStatusCode();
6161

62-
string responseText = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); //Make sure it is synchronous
62+
string responseText = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); //Make sure it is synchronous
6363
tracingService.Trace(responseText);
6464
//Log success in the Plugin Trace Log:
6565
tracingService.Trace("HttpClientPlugin completed successfully.");

powerapps-docs/developer/data-platform/troubleshoot-plug-in.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ This error simply means that the worker process running your plug-in code crashe
3838

3939
As mentioned in [Handle exceptions in plug-ins](handle-exceptions.md), when you write a plug-in you should try to anticipate which operations may fail and wrap them in a try-catch block. When any errors occur, you should use the <xref:Microsoft.Xrm.Sdk.InvalidPluginExecutionException> to gracefully terminate the operation with an error meaningful to the user.
4040

41-
A common scenario for this is when using a the [HttpClient.SendAsync Method](/dotnet/api/system.net.http.httpclient.sendasync?view=netframework-4.6.2) or [HttpClient.GetAsync Method](/dotnet/api/system.net.http.httpclient.getasync?view=netframework-4.6.2) which are asynchronous operations that returns a [Task](/dotnet/api/system.threading.tasks.task-1?view=netframework-4.6.2). To make this work in a plug-in where code needs to be synchronous, people may use the [Task&lt;TResult&gt;.Result Property](/dotnet/api/system.threading.tasks.task-1.result?view=netframework-4.6.2). When an error occurs, this returns an [AggregateException](/dotnet/api/system.aggregateexception?view=netframework-4.6.2) which consolidates multiple failures into a single exception which can be difficult to handle. A better design is to use [Task&lt;TResult&gt;.ConfigureAwait(false)](/dotnet/api/system.threading.tasks.task-1.configureawait?view=netframework-4.6.2).[GetAwaiter()](/dotnet/api/system.aggregateexception?view=netframework-4.6.2).[GetResult()](/dotnet/api/system.runtime.compilerservices.taskawaiter-1.getresult?view=netframework-4.6.2) because it propagates the results as the specific error that caused the failure.
41+
A common scenario for this is when using a the [HttpClient.SendAsync Method](/dotnet/api/system.net.http.httpclient.sendasync?view=netframework-4.6.2) or [HttpClient.GetAsync Method](/dotnet/api/system.net.http.httpclient.getasync?view=netframework-4.6.2) which are asynchronous operations that returns a [Task](/dotnet/api/system.threading.tasks.task-1?view=netframework-4.6.2). To make this work in a plug-in where code needs to be synchronous, people may use the [Task&lt;TResult&gt;.Result Property](/dotnet/api/system.threading.tasks.task-1.result?view=netframework-4.6.2). When an error occurs, this returns an [AggregateException](/dotnet/api/system.aggregateexception?view=netframework-4.6.2) which consolidates multiple failures into a single exception which can be difficult to handle. A better design is to use [Task&lt;TResult&gt;.GetAwaiter()](/dotnet/api/system.threading.tasks.task-1.getawaiter?view=netframework-4.6.2).[GetResult()](/dotnet/api/system.runtime.compilerservices.taskawaiter-1.getresult?view=netframework-4.6.2) because it propagates the results as the specific error that caused the failure.
4242

4343
The following example shows the correct way to manage the exception and an outbound call using [HttpClient.GetAsync Method](/dotnet/api/system.net.http.httpclient.getasync?view=netframework-4.6.2). This plug-in will attempt to get the response text for a Url set in the unsecure config for a step registered for it.
4444

@@ -93,12 +93,12 @@ namespace ErrorRepro
9393
client.Timeout = TimeSpan.FromMilliseconds(15000); //15 seconds
9494
client.DefaultRequestHeaders.ConnectionClose = true; //Set KeepAlive to false
9595
96-
HttpResponseMessage response = client.GetAsync(webAddress).ConfigureAwait(false).GetAwaiter().GetResult(); //Make sure it is synchronous
96+
HttpResponseMessage response = client.GetAsync(webAddress).GetAwaiter().GetResult(); //Make sure it is synchronous
9797
response.EnsureSuccessStatusCode();
9898

9999
tracingService.Trace($"ErrorRepro.AsyncError.GetWebResponse succeeded.");
100100

101-
string responseContent = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); //Make sure it is synchronous
101+
string responseContent = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); //Make sure it is synchronous
102102
103103
tracingService.Trace($"ErrorRepro.AsyncError.GetWebResponse responseContent parsed successfully.");
104104

0 commit comments

Comments
 (0)