Esempio n. 1
0
        public WeakReference(T target, IReferenceQueue <T> queue, bool trackResurrection)
            : base(queue)
        {
            systemReference = new System.WeakReference(target, trackResurrection);

            CreateFinalizerListener();
        }
 public KeyedTimedReference(K key, V reference, IReferenceQueue <V> referenceQueue, TimeSpan timeout)
     : base(reference, referenceQueue)
 {
     this.Key           = key;
     this.HardReference = reference;
     this.LastAccess    = DateTime.Now;
     this.TimeOut       = timeout;
 }
Esempio n. 3
0
        /// <summary>
        /// Constructs a new <see cref="TimedReference{T}"/>
        /// </summary>
        /// <param name="target">The reference target</param>
        /// <param name="timeout">
        /// The minimum amount of time the reference target should be uncollectable for
        /// after each access to the <see cref="Target"/> property.
        /// </param>
        /// <param name="queue">The references associated <see cref="IReferenceQueue{T}"/></param>
        /// <param name="trackResurrection">
        /// True if the current reference should continue to reference the <see cref="Target"/>
        /// after it has been resurrected.
        /// </param>
        public TimedReference(T target, TimeSpan timeout, IReferenceQueue <T> queue, bool trackResurrection)
            : base(queue)
        {
            hardReference   = target;
            timeOut         = timeout;
            targetTime      = DateTime.Now + timeout;
            systemReference = new System.WeakReference(target, trackResurrection);

            CreateTimer();
            CreateFinalizerListener();
        }
Esempio n. 4
0
        /// <summary>
        /// Places this reference onto its associated <see cref="IReferenceQueue{T}"/>.
        /// </summary>
        /// <returns>
        /// True if the <see cref="Reference{T}"/> was placed on the <see cref="IReferenceQueue{T}"/>
        /// otherwise False if no <see cref="IReferenceQueue{T}"/> is associated or if the
        /// <see cref="Reference{T}"/> has already been enqueued.
        /// </returns>
        protected virtual bool Enqueue()
        {
            if (referenceQueue != null && nextOnQueue == null)
            {
                referenceQueue.Enqueue(this);
                referenceQueue = null;

                return(true);
            }

            return(false);
        }
Esempio n. 5
0
 public WeakReference(T target, IReferenceQueue <T> queue)
     : this(target, queue, false)
 {
 }
Esempio n. 6
0
 /// <summary>
 /// Constructs a new <see cref="Reference{T}"/>
 /// </summary>
 /// <param name="referenceQueue">The reference's associated <see cref="IReferenceQueue{T}"/></param>
 protected Reference(IReferenceQueue <T> referenceQueue)
 {
     this.referenceQueue = referenceQueue;
 }
Esempio n. 7
0
 /// <summary>
 /// Constructs a new <see cref="Reference{T}"/>
 /// </summary>
 protected Reference()
 {
     referenceQueue = null;
 }
Esempio n. 8
0
 /// <summary>
 /// Constructs a new <see cref="TimedReference{T}"/>
 /// </summary>
 /// <param name="target">The reference target</param>
 /// <param name="timeout">
 /// The minimum amount of time the reference target should be uncollectable for
 /// after each access to the <see cref="Target"/> property.
 /// </param>
 /// <param name="queue">The references associated <see cref="IReferenceQueue{T}"/></param>
 public TimedReference(T target, TimeSpan timeout, IReferenceQueue <T> queue)
     : this(target, timeout, queue, false)
 {
 }
Esempio n. 9
0
 public KeyedWeakReference(K key, V reference, IReferenceQueue <V> referenceQueue)
     : base(reference, referenceQueue)
 {
     this.Key = key;
 }