CamHart
CamHart

Reputation: 4335

Is HttpClientExtension.PostAsJsonAsync thread safe?

The correct way to use HttpClient, is to create one for the lifetime of the application. However, there are only a subset of methods on HttpClient that are thread safe. (see https://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.110).aspx#Anchor_5)

My question is, are HttpClientExtension methods thread safe, like PostAsJsonAsync.

I understand that it's an extension method, which basically means its a static method. However if it uses a thread unsafe method of the HttpClient passed in, then it wouldn't be thread safe. There's also the slight chance that some static state is maintained internally (I really hope not), as well.

I've tried looking for source code but couldn't find it, and I can't find any documentation about it.

Upvotes: 0

Views: 413

Answers (1)

egnomerator
egnomerator

Reputation: 1105

Based on this reference, I believe it is thread safe.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Upvotes: 3

Related Questions