Is this code thread-safe?
Posted
by mafutrct
on Stack Overflow
See other posts from Stack Overflow
or by mafutrct
Published on 2010-04-04T15:59:52Z
Indexed on
2010/04/04
16:03 UTC
Read the original article
Hit count: 376
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.)
© Stack Overflow or respective owner