Пример #1
0
 public WeakCollection(IEqualityComparer <T> comparer, bool autoRemoveDeadItems)
 {
     _comparer = comparer ?? EqualityComparer <T> .Default;
     _wrapped  = new ThreadSafeCollection <TNeedle>();
     if (autoRemoveDeadItems)
     {
         RegisterForAutoRemoveDeadItemsExtracted();
     }
     else
     {
         GC.SuppressFinalize(this);
     }
 }
        public StrongDelegateCollection(bool freeReentry)
        {
            IEqualityComparer <Delegate> comparer = EqualityComparer <Delegate> .Default;

            _wrapped = new ThreadSafeCollection <Delegate>(comparer);
            if (freeReentry)
            {
                _invoke                      = InvokeExtracted;
                _invokeAndClear              = InvokeAndClearExtracted;
                _invokeWithException         = InvokeExtracted;
                _invokeAndClearWithException = InvokeAndClearExtracted;
            }
            else
            {
                var guard = new ReentryGuard();
                _invoke                      = input => guard.Execute(() => InvokeExtracted(input));
                _invokeAndClear              = input => guard.Execute(() => InvokeAndClearExtracted(input));
                _invokeWithException         = (onException, input) => guard.Execute(() => InvokeExtracted(onException, input));
                _invokeAndClearWithException = (onException, input) => guard.Execute(() => InvokeAndClearExtracted(onException, input));
            }
        }