Should i use static lock object or instance object?

Viewed 46

I am working with an asp.net webapi program (not .net core). there is a class that has read/write files function. in order to keep the thread-safe, I want to add a lock.

someone suggest below code:

private static readonly object Locker = new object();

And someone suggests I should use an instance locker. which is correct? what's the scope of the locker?

if the program creates multiple instances, will the locker still work?

Or should I make this class Singleton?

0 Answers
Related