All resources available through these methods must be thread safe. In your case, this is not so. If you look at the HttpClient documentation, it says:
All public static (Shared in Visual Basic) members of this type are thread safe. Any instance members do not guarantee thread safety .
You call the instance method ( client.GetAsync ), which does not guarantee that it will be thread safe, which could potentially cause problems for you.
To reduce this, you can:
- create a new (local)
HttpClient for each call. - synchronize access to
client (for example, by means of blocking).
In addition, I cannot say whether PrintResult be thread safe, but Console.WriteLine should be thread safe.
source share