Skip to content

Commit eb3de4d

Browse files
authored
Updates
1 parent fd4d311 commit eb3de4d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

aspnetcore/blazor/call-web-api.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,24 @@ The solution includes a demonstration of obtaining weather data securely via an
358358
359359
## Disposal of `HttpRequestMessage`, `HttpResponseMessage`, and `HttpClient`
360360
361-
An <xref:System.Net.Http.HttpRequestMessage> without a body doesn't require explicit disposal with a `using` declaration (C# 8 or later, example: `using var request = new HttpRequestMessage(...);`) or a [`using` block (all C# releases, example: `using (var request = new HttpRequestMessage(...)) { ... }`)](/dotnet/csharp/language-reference/keywords/using), but we recommend disposing with every use for the following reasons:
361+
An <xref:System.Net.Http.HttpRequestMessage> without a body doesn't require explicit disposal. However, you can dispose of it with either of the following patterns:
362+
363+
* `using` declaration (C# 8 or later):
364+
365+
```csharp
366+
using var request = new HttpRequestMessage(...);
367+
```
368+
369+
* [`using` block (all C# releases)](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/using):
370+
371+
```csharp
372+
using (var request = new HttpRequestMessage(...))
373+
{
374+
...
375+
}
376+
```
377+
378+
We recommend disposing of every <xref:System.Net.Http.HttpRequestMessage> with every use for the following reasons:
362379
363380
* To gain a performance improvement by avoiding finalizers.
364381
* It hardens the code for the future in case a request body is ever added to an <xref:System.Net.Http.HttpRequestMessage> that didn't initially have one.

0 commit comments

Comments
 (0)