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
The HttpClient instance should be held to as mush as possible. It should have been possible to pass a HttpClient to Sender, as to prevent Sender from going out of scope and "killing" its internal HttpClient instance. Microsoft own words:
HttpClient is intended to be instantiated once and re-used throughout the life of an application. Especially in server applications, creating a new HttpClient instance for every request will exhaust the number of sockets available under heavy loads. This will result in SocketException errors.
There are a few ways to implement this: allow Sender to be configured with an HttpClient instance created elsewhere, make HttpClient static, create a Settings class which holds the HttpClient instance and lives outside the scope of Sender, etc.
Maybe you've created Sender to live as long as the application (just like the HttpClient), but if so then the sample code is misleading since it surrounds the instantiation of the Sender class with a using clause, suggesting it should be disposed as soon as possible (and its own HttpClient together with it).
The text was updated successfully, but these errors were encountered:
rburnham52
pushed a commit
to rburnham52/FCM.Net
that referenced
this issue
Feb 6, 2018
The HttpClient instance should be held to as mush as possible. It should have been possible to pass a HttpClient to Sender, as to prevent Sender from going out of scope and "killing" its internal HttpClient instance. Microsoft own words:
(found here: https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client )
There are a few ways to implement this: allow Sender to be configured with an HttpClient instance created elsewhere, make HttpClient static, create a Settings class which holds the HttpClient instance and lives outside the scope of Sender, etc.
Maybe you've created Sender to live as long as the application (just like the HttpClient), but if so then the sample code is misleading since it surrounds the instantiation of the Sender class with a using clause, suggesting it should be disposed as soon as possible (and its own HttpClient together with it).
The text was updated successfully, but these errors were encountered: