Skip to content

Commit 35ea732

Browse files
authored
Use static HttpClient (#45026)
1 parent 7d0f665 commit 35ea732

File tree

5 files changed

+48
-30
lines changed

5 files changed

+48
-30
lines changed

docs/framework/ui-automation/implementing-the-ui-automation-expandcollapse-control-pattern.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ When implementing the ExpandCollapse control pattern, note the following guideli
3838

3939
- Calling <xref:System.Windows.Automation.ExpandCollapsePattern.Expand%2A> on a TreeItem may display all descendants or only immediate children.
4040

41-
- If calling <xref:System.Windows.Automation.ExpandCollapsePattern.Expand%2A> or <xref:System.Windows.Automation.ExpandCollapsePattern.Collapse%2A> on a control maintains the state of its descendants, a visibility change event should be sent, not a state change event If the parent control does not maintain the state of its descendants when collapsed, the control may destroy all the descendants that are no longer visible and raise a destroyed event; or it may change the <xref:System.Windows.Automation.Provider.IExpandCollapseProvider.ExpandCollapseState%2A> for each descendant and raise a visibility change event.
41+
- If calling <xref:System.Windows.Automation.ExpandCollapsePattern.Expand%2A> or <xref:System.Windows.Automation.ExpandCollapsePattern.Collapse%2A> on a control maintains the state of its descendants, a visibility change event should be sent, not a state change event If the parent control does not maintain the state of its descendants when collapsed, the control may destroy all the descendants that are no longer visible and raise a destroyed event; or it might change the <xref:System.Windows.Automation.Provider.IExpandCollapseProvider.ExpandCollapseState%2A> for each descendant and raise a visibility change event.
4242

4343
- To guarantee navigation, it is desirable for an object to be in the UI Automation tree (with appropriate visibility state) regardless of its parents <xref:System.Windows.Automation.ExpandCollapseState>. If descendants are generated on demand, they may only appear in the UI Automation tree after being displayed for the first time or only while they are visible.
4444

docs/framework/unmanaged-api/debugging/icordebugprocess-gethelperthreadid-method.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ HRESULT GetHelperThreadID (
3838

3939
During managed and unmanaged debugging, it is the debugger's responsibility to ensure that the thread with the specified ID remains running if it hits a breakpoint placed by the debugger. A debugger may also wish to hide this thread from the user. If no helper thread exists in the process yet, the `GetHelperThreadID` method returns zero in *`pThreadID`.
4040

41-
You cannot cache the thread ID of the helper thread, because it may change over time. You must re-query the thread ID at every stopping event.
41+
You cannot cache the thread ID of the helper thread, because it might change over time. You must re-query the thread ID at every stopping event.
4242

4343
The thread ID of the debugger's helper thread will be correct on every unmanaged [ICorDebugManagedCallback::CreateThread](icordebugmanagedcallback-createthread-method.md) event, thus allowing a debugger to determine the thread ID of its helper thread and hide it from the user. A thread that is identified as a helper thread during an unmanaged `ICorDebugManagedCallback::CreateThread` event will never run managed user code.
4444

docs/fundamentals/networking/http/httpclient-guidelines.md

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,43 +58,18 @@ For more information about managing `HttpClient` lifetime with `IHttpClientFacto
5858

5959
It's possible to configure a `static` or *singleton* client to use any number of resilience pipelines using the following pattern:
6060

61-
```csharp
62-
using System;
63-
using System.Net.Http;
64-
using Microsoft.Extensions.Http;
65-
using Microsoft.Extensions.Http.Resilience;
66-
using Polly;
67-
68-
var retryPipeline = new ResiliencePipelineBuilder<HttpResponseMessage>()
69-
.AddRetry(new HttpRetryStrategyOptions
70-
{
71-
BackoffType = DelayBackoffType.Exponential,
72-
MaxRetryAttempts = 3
73-
})
74-
.Build();
75-
76-
var socketHandler = new SocketsHttpHandler
77-
{
78-
PooledConnectionLifetime = TimeSpan.FromMinutes(15)
79-
};
80-
var resilienceHandler = new ResilienceHandler(retryPipeline)
81-
{
82-
InnerHandler = socketHandler,
83-
};
84-
85-
var httpClient = new HttpClient(resilienceHandler);
86-
```
61+
:::code language="csharp" source="snippets/httpclient-guidelines/MyClass.cs":::
8762

8863
The preceding code:
8964

9065
- Relies on [Microsoft.Extensions.Http.Resilience](https://www.nuget.org/packages/Microsoft.Extensions.Http.Resilience) NuGet package.
9166
- Specifies a transient HTTP error handler, configured with retry pipeline that with each attempt will exponentially backoff delay intervals.
9267
- Defines a pooled connection lifetime of fifteen minutes for the `socketHandler`.
9368
- Passes the `socketHandler` to the `resilienceHandler` with the retry logic.
94-
- Instantiates an `HttpClient` given the `resilienceHandler`.
69+
- Instantiates a shared `HttpClient` given the `resilienceHandler`.
9570

9671
> [!IMPORTANT]
97-
> The `Microsoft.Extensions.Http.Resilience` library is currently marked as [experimental](../../../csharp/language-reference/attributes/general.md#experimental-attributes) and it may change in the future.
72+
> The `Microsoft.Extensions.Http.Resilience` library is currently marked as [experimental](../../../csharp/language-reference/attributes/general.md#experimental-attributes) and it might change in the future.
9873
9974
## See also
10075

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Microsoft.Extensions.Http.Resilience;
2+
using Polly;
3+
4+
class MyClass
5+
{
6+
static HttpClient? httpClient;
7+
8+
MyClass()
9+
{
10+
var retryPipeline = new ResiliencePipelineBuilder<HttpResponseMessage>()
11+
.AddRetry(new HttpRetryStrategyOptions
12+
{
13+
BackoffType = DelayBackoffType.Exponential,
14+
MaxRetryAttempts = 3
15+
})
16+
.Build();
17+
18+
var socketHandler = new SocketsHttpHandler
19+
{
20+
PooledConnectionLifetime = TimeSpan.FromMinutes(15)
21+
};
22+
var resilienceHandler = new ResilienceHandler(retryPipeline)
23+
{
24+
InnerHandler = socketHandler,
25+
};
26+
27+
httpClient = new HttpClient(resilienceHandler);
28+
}
29+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.2.0" />
12+
</ItemGroup>
13+
14+
</Project>

0 commit comments

Comments
 (0)