Is this code thread-safe?
- by mafutrct
I've got a class with several properties. On every value update, a Store method is called with stores all fields (in a file).
private int _Prop1;
public int Prop1 {
get {
return _Prop1;
}
set {
_Prop1 = value;
Store();
}
}
// more similar properties here...
private XmlSerializer _Ser = new ...;
private void Store()
{
lock (_Ser) {
using (FileStream fs = new ...) {
_Ser.Serialize (fs, this);
}
}
}
Is this design thread-safe?
(Btw, if you can think of a more appropriate caption, feel free to edit.)