Reputation: 8042
I am using TvdbLib in a program. This library can use a cache for loading TV series quicker. To further improve the speed of the program, I do all my loading of TV series on separate threads. When two threads run simultaneously and try to read/write from the cache simultaneously, I will get the following error:
The process cannot access the file 'C:\BinaryCache\79349\series_79349.ser' because it is being used by another process.
Does anyone know how to avoid this and still have the program running smoothly?
Upvotes: 0
Views: 181
Reputation: 9639
From the error I assume that TvdbLib does not support multiple concurrent threads accessing the same cache. As it is an open source project, you could get the source code and implement your own protection around the cache access, e.g., using the lock statement. Of course, you could lock within your own code before it calls TvdbLib, but because this will be a higher level, the lock will be maintained for longer and you may not get the fine-grained concurrency that you want.
Upvotes: 0
Reputation: 816
You can use the lock statement to ensure only one thread is accessing the cache at the same time:
http://msdn.microsoft.com/en-us/library/c5kehkcz(v=vs.71).aspx
Upvotes: 1
Reputation: 70369
CacheProvider
is not built for being used in multi-threaded scenarios... either use it in one thread only or lock
on every access via a shared object
or supply every thread with its own CacheProvider
and its own distinct _root
directory (in the constructor).
Upvotes: 2