I’m using property like this in multithreading application (WCF service hosted in windows managed service):
private object lockObj = new object();
private string val = string.Empty;
[DataMember]
public string Value
{
get
{
lock(lockObj)
{
return val;
}
}
set
{
lock(lockObj)
{
val = value;
}
}
}
Sending via WCF service fails until I remove the locks, then it works. (don’t have current exception, service fails without loging to my tracking)
Is there possibility to solve it with having locks, or I must to convert it to some reduced object without locks?
so as I get no answer, I write my own solution.
as I write in comments, type of Value property is
List<string>(later changed toList<SomeMyObject>) and when I remove locks, I got exceptions because of collection is modified. Then I make a method, which makes a DeepCopy of my list and what I send through WCF is Skelet version (from all inner objects I take just Ids) of previous object:on SO found DeepClone method: