示例#1
0
        internal static bool Cleanup <TKey, TMessage, TResult>(this XCollection_KeyMessageResult <TKey, TMessage, TResult> collection)
            where TKey : notnull
        {// lock required
            foreach (var x in collection.Dictionary)
            {
                var list  = x.Value;
                var array = list.GetValues();
                for (var i = 0; i < array.Length; i++)
                {
                    if (array[i] is { } c)
                    {
                        if (c.WeakDelegate?.IsAlive == false)
                        {
                            c.Dispose();
                        }
                    }
                }

                if (list.Shrink() && collection.Count >= CrossChannelConst.HoldDictionaryThreshold)
                {
                    collection.Dictionary.TryRemove(x.Key, out _);
                    collection.Count--;
                    list.Dispose();
                }
            }

            return(collection.Count == 0);
        }
示例#2
0
 static Cache_KeyMessageResult()
 {
     Collection = new();
 }