重构单对象缓存,使用并行字典解决多线程死锁的问题
大石头 authored at 2017-09-29 18:11:06
625.00 B
X

using System.Collections.Concurrent;

namespace System
{
    /// <summary>
    /// 
    /// </summary>
    public static class ConcurrentDictionaryExtensions
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="dict"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static Boolean Remove<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dict, TKey key)
        {
            return dict.TryRemove(key, out var value);
        }
    }
}