0

I'm using google drive API in a multi-thread C# application. I would like to know if the Google dot net client library it's thread-safe or not.

Also I would like to know what's more right:

create a singelton service, or a new service every time.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449

2 Answers2

1

If you are asking if the Google .net client Library is thread safe. I am pretty sure that it is. It is noted in at least one place in the documentation that it is thread safe.

Google APIs Client Library for .NET

UserCredential is a thread-safe helper class for using an access token to access protected resources. An access token typically expires after 1 hour, after which you will get an error if you try to use it.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • I saw that too, but if it is mentioned only there (I couldn't find more places), doesn't that mean that only this is thread-safe? – user3131889 Feb 18 '15 at 07:58
  • Don't think so but I can ping the Developer on the project and find out for sure. Please go read this http://stackoverflow.com/help/how-to-ask – Linda Lawton - DaImTo Feb 18 '15 at 08:00
  • 1
    The library main classes are thread-safe, such as Google.Apis.Requests.ClientServiceRequest, Google.Apis.Services.BaseClientService and Google.Apis.Auth.OAuth2.UserCredential (as you mentioned). There are other classes which are not, such as the resources themselves. So, regarding your question, services and requests are implemented as thread-safe. There is only one issue that I'm aware of - https://code.google.com/p/google-api-dotnet-client/issues/detail?id=466, and the main problem there is when you use several MediaUpload method in the same time. – peleyal Feb 18 '15 at 15:11
0

It isn't. I've tried writing some code assuming it was, and my code would sometimes randomly crash at the "request.Execute()"s...

I tried using a mutex and so only one thread was using a singleton service at a time: that reduced the crashes but it didn't eliminate them.

Leaving the mutex in, I changed it to a singleton UserCredential and use a new service for each thread and it hasn't crashed since. (I don't know if I need the mutex anymore or not, but the google api calls aren't critical path for my application, I just needed to get the calls out of the main thread.)