// AsReadOnly #endregion public void ReadFile(string file_path) { LockList.PerformUsingWriteLock(() => { if (File.Exists(file_path)) { using (var file = File.OpenRead(file_path)) { //ProtoBuf.Serializer.Serialize<Dictionary<string, string>>(file, cacheData); file.Position = 0; m_TList = boisSerializer.Deserialize <List <T> >(file); file.Close(); } } }); }
// Init #endregion #region IDictionary<TKey,TValue> Members #region GetValueAddIfNotExist /// <summary> /// Returns the value of <paramref name="key"/>. If <paramref name="key"/> /// does not exist, <paramref name="func"/> is performed and added to the /// dictionary /// </summary> /// <param name="key">the key to check</param> /// <param name="func">the delegate to call if key does not exist</param> public TValue GetValueAddIfNotExist(TKey key, Func <TValue> func) { // enter a write lock, to make absolutely sure that the key // is added/deleted from the time we check if it exists // to the time we add it if it doesn't exist return(Lock_Dictionary.PerformUsingUpgradeableReadLock(() => { TValue rVal; // if we have the value, get it and exit if (m_Dictionary.TryGetValue(key, out rVal)) { return rVal; } // not found, so do the function to get the value Lock_Dictionary.PerformUsingWriteLock(() => { rVal = func.Invoke(); // add to the dictionary m_Dictionary.Add(key, rVal); // return the value return rVal; }); return rVal; })); }
/// <summary> /// Clears the collection /// </summary> public void Clear() { LockStack.PerformUsingWriteLock(() => m_stack.Clear()); }