I have a WCF application which receives some string arrays from client applications. Then, these arrays are passed as parameters to the constructors of some custom classes. I am not, myself, creating any threads (not even using System.Threading), but I would like to know if it is bad pratice to use lock (param.SyncRoot) in each constructor just to play on the safe side? That’s because I am making all my objects immutable, and I want to assure the arrays aren’t changed in any way.
I have a WCF application which receives some string arrays from client applications. Then,
Share
I think you are overcomplicating things.
One of the main things to keep things as easy as possible with threads is to have a clear idea of responsibilities for locking. Thus if you are not creating any threads, you do not need to lock, your locking is just making things complex, but not adding any value – a bad library will still fail.
The locking should be done inside the objects which you create and use.