@@ -89,6 +89,8 @@ public class CSubStation : CPropNotificationClass, IHasParent , IHasID , IXmlSer
8989 /// </summary>
9090 /// <autogeneratedoc />
9191 public static Dictionary < long , CSubStation > SubStations = new Dictionary < long , CSubStation > ( ) ;
92+
93+ private static readonly object SubStationsSync = new object ( ) ;
9294 #endregion
9395
9496 #region Interface properties
@@ -137,7 +139,11 @@ public CSubStation(CStation cStation, long idSubstation, string sDescription)
137139 Station = cStation ;
138140 this . idSubStation = idSubstation ;
139141 Description = sDescription ;
140- SubStations [ idSubStation ] = this ;
142+
143+ lock ( SubStationsSync )
144+ {
145+ SubStations [ idSubStation ] = this ;
146+ }
141147 }
142148
143149 /// <summary>
@@ -149,10 +155,13 @@ public CSubStation(CStation cStation, long idSubstation, string sDescription)
149155 /// <autogeneratedoc />
150156 private void OnChangeIdSubStation ( long oldId , long newId , string name )
151157 {
152- if ( oldId > 0 )
153- RemoveSubStation ( oldId ) ;
154- if ( newId > 0 )
155- SubStations [ newId ] = this ;
158+ lock ( SubStationsSync )
159+ {
160+ if ( oldId > 0 )
161+ SubStations . Remove ( oldId ) ;
162+ if ( newId > 0 )
163+ SubStations [ newId ] = this ;
164+ }
156165 }
157166
158167 /// <summary>
@@ -163,7 +172,10 @@ private void OnChangeIdSubStation(long oldId, long newId, string name)
163172 /// <autogeneratedoc />
164173 private static void RemoveSubStation ( long oldId )
165174 {
166- SubStations . Remove ( oldId ) ;
175+ lock ( SubStationsSync )
176+ {
177+ SubStations . Remove ( oldId ) ;
178+ }
167179 }
168180
169181 #region Interface methods
@@ -249,7 +261,10 @@ public void WriteXml(XmlWriter writer)
249261 /// <autogeneratedoc />
250262 public static CSubStation GetSubStationGetStation ( long idSubStation )
251263 {
252- return SubStations . ContainsKey ( idSubStation ) ? SubStations [ idSubStation ] : null ;
264+ lock ( SubStationsSync )
265+ {
266+ return SubStations . ContainsKey ( idSubStation ) ? SubStations [ idSubStation ] : null ;
267+ }
253268 }
254269 #endregion
255270 #endregion
0 commit comments