Documentation confusion about multi-threading City calls
washamdev opened this issue · 3 comments
In the documentation at http://maxmind.github.io/GeoIP2-dotnet/, under the "City Service (Sync)" section, it states this:
This creates a WebServiceClient object that can be reused across requests.
But the example shows this code sample:
using (var client = new WebServiceClient(42, "license_key"))
That obviously does not create a reusable WebServiceClient
object, as it is disposed of at the end of the using statement, so what does the comment mean that it can be "reused across requests"?
We were interested in creating one WebServiceClient
object and using that to convert all IPs to geo, but we're assuming one WebServiceClient
can't handle multiple threads using one object to check IPs, correct?
You can reuse the object across threads if you'd like as the docs suggest. There isn't much performance gain except slightly less GC pressure.
So you're saying the WebServiceClient
object is thread safe, in that it can handle one or more IP checks at the same time without overwriting a request that was already in process? And you're also saying that doing it that way isn't a significant upgrade over just creating a WebServiceClient
object for each request (thread)?
Yes, that is correct on both accounts.