You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your implementation of the usage from the HttpClient is bad.
Unfortunately, correct lifetime management of HttpClient is one of the biggest gotchas in .NET, MS really needs to fix it: it's unreasonable to expect people to understand concepts like socket-exhaustion and such when all they want to do is make a web-request every 15 minutes in a Windows Service, for example.
So a better solution is using a IHttpClientFactory to create the HttpClient for each single request. Maybe you can realize this with HttpClientFactory.CreateHttpClient.
This would be a better solution, but there are still a lot of issues with it:
There is no way for me to set a UserClient (ApplicationName) for the HttpClient.
There is no way for me to configure a Proxy server.
There is no way for me to log HTTP requests.
To let me do all of this, it would be nice if you would implement a Callback function, how I can create the HttpClient by myself.
You could realize this, for example, with a static event in your Helpers.cs file. If you invoke this event before each HttpClient usage, I could create my own HttpClient every time fresh. And if I don't register to the event, you could use your static HttpClient furthermore.
This solution should be not a lot of work for you.
If you are interested, I would realize this and offer with a Pull Request to you.
What do you thing?
The text was updated successfully, but these errors were encountered:
Your implementation of the usage from the
HttpClient
is bad.Unfortunately, correct lifetime management of
HttpClient
is one of the biggest gotchas in .NET, MS really needs to fix it: it's unreasonable to expect people to understand concepts like socket-exhaustion and such when all they want to do is make a web-request every 15 minutes in a Windows Service, for example.So a better solution is using a
IHttpClientFactory
to create theHttpClient
for each single request. Maybe you can realize this withHttpClientFactory.CreateHttpClient
.This would be a better solution, but there are still a lot of issues with it:
UserClient
(ApplicationName
) for theHttpClient
.To let me do all of this, it would be nice if you would implement a Callback function, how I can create the
HttpClient
by myself.You could realize this, for example, with a static event in your
Helpers.cs
file. If you invoke this event before eachHttpClient
usage, I could create my ownHttpClient
every time fresh. And if I don't register to the event, you could use your staticHttpClient
furthermore.This solution should be not a lot of work for you.
If you are interested, I would realize this and offer with a Pull Request to you.
What do you thing?
The text was updated successfully, but these errors were encountered: