R
rosco
I have a multi threading application where multiple threads can read
and write to the property.
I try to avoid the lock statement on properties that hold none
business critical data.
I could create a special '_propertyLock' object for this none critical
data but this could lead to more multithreading problems like
deadlocks.
I am just looking for atomic read a write operation to a string. There
is a Read member but only for typeof long.
Can I use Interlocked on a string?
private string _name
public string Name
{
get { return _name; }
set { System.Threading.Interlocked.Exchange(ref _name,
value);
}
I TRY TO AVOID ...
private object _propertyLock1 = new object()
private string _name1
public string Name1
{
get { lock(propertyLock1 ){return _name1; }}
set { lock(propertyLock1 ){_name1 = value;}}
}
private object _propertyLock2 = new object()
private string _name2
public string Name2
{
get { lock(propertyLock 2){return _name2; }}
set { lock(propertyLock 2){_name = value2;}}
}
and write to the property.
I try to avoid the lock statement on properties that hold none
business critical data.
I could create a special '_propertyLock' object for this none critical
data but this could lead to more multithreading problems like
deadlocks.
I am just looking for atomic read a write operation to a string. There
is a Read member but only for typeof long.
Can I use Interlocked on a string?
private string _name
public string Name
{
get { return _name; }
set { System.Threading.Interlocked.Exchange(ref _name,
value);
}
I TRY TO AVOID ...
private object _propertyLock1 = new object()
private string _name1
public string Name1
{
get { lock(propertyLock1 ){return _name1; }}
set { lock(propertyLock1 ){_name1 = value;}}
}
private object _propertyLock2 = new object()
private string _name2
public string Name2
{
get { lock(propertyLock 2){return _name2; }}
set { lock(propertyLock 2){_name = value2;}}
}