I am developing an asp.net webapi project. a controller action method will check local files and download updated files if the locals get expired. Since this action may be requested by multiple clients at the same time, so I am afraid there will be file Concurrency issue.
in my downloadService
class, I consider using ReaderWriterLock
.
question 1: where should I init the ReaderWriterLock
? should I keep it as a private member?
private readonly ReaderWriterLock asyncReaderWriterLock = new();
Or should I each time create it in the fileWrite
method?
question 2: assume it's an instance member, if there're multiple downloadService
objects, then there will be a lot of locks. will it still work?
does this lock file or code?
question 3: if there're 100 files, when I operate File A, it should not affect file B. which means, thread B can write File B at the same time when thread A writes file A. so do I need to assign 100 locks for these files?
Thanks