Guest User

Untitled

a guest
Aug 14th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. Thread-safe access to static collection
  2. private static Dictionary<Type, List<PropertyInfo>> PropertyCache { get; set; }
  3.  
  4. // I will do this
  5. PropertyCache.Add(typeof(string), new List<PropertyInfo>());
  6. PropertyCache.Remove(typeof(string));
  7.  
  8. // I will never do this
  9. PropertyCache = new Dictionary<Type, List<PropertyInfo>>();
  10.  
  11. lock(((ICollection)myObject).SyncRoot)
  12. {
  13. //Code that should be executed by only one concurrent thread
  14. //This is add/insert/remove/iterate/clear/etc.
  15. }
Add Comment
Please, Sign In to add comment