Click or drag to resize
ExpiringCollectionTItem Class
Manages a self-expiring collection of items.
Inheritance Hierarchy

Namespace: VirtualRadar.Interface
Assembly: VirtualRadar.Interface (in VirtualRadar.Interface.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public abstract class ExpiringCollection<TItem> : IDisposable
where TItem : class

Type Parameters

TItem
The type of item being held by the collection.

The ExpiringCollectionTItem type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyAfterCheckForExpiredItemsDelegate
Gets or sets an optional delegate that is called after the check for expired items is made.
Public propertyBeforeCheckForExpiredItemsDelegate
Gets or sets an optional delegate that is called before the check is made for expired items.
Public propertyCount
When overridden by the derivee this returns the current count of items in the collection.
Public propertyCountChangedDelegate
Gets or sets an optional delegate that is called when the count changes. The new count is passed to the delegate. The list is locked to the calling thread while the delegate is running. The delegate will occasionally be called on a background thread.
Public propertyExpireMilliseconds
Gets or sets the minimum number of milliseconds that an item can remain within the list.
Public propertyMillisecondsBetweenChecks
Gets or sets the minimum number of milliseconds to wait between checks for expiring items.
Top
Methods
  NameDescription
Public methodChangeIntervals
Changes the intervals for the expiration of items and the interval between checks.
Public methodClear
When overridden by a derivee this clears the collection and unhooks all events.
Public methodDispose
See interface docs.
Protected methodDispose(Boolean)
Disposes of or finalises the object.
Protected methodDoRemoveExpiredItems
When overridden by the derivee this should remove all items that have a timestamp that is less than or equal to the threshold passed across.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Finalises the object.
(Overrides ObjectFinalize.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodHookHeartbeat
Hooks the heartbeat event. Must be called from within a lock.
Public methodLock
Calls the action passed across with the list locked. Do not perform an action that will attempt to lock the list from another thread, it will block.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnCountChanged
Called by the derivee to inform the owner of the collection that the count has changed. Always call this from within a lock.
Public methodRemoveExpiredItems
Removes expired items.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Protected methodUnhookHeartbeat
Unhooks the heartbeat service if hooked. Must be called from within a lock.
Top
Fields
  NameDescription
Protected field_Clock
The clock that provides timestamps.
Protected field_SyncLock
The lock object that controls access to the other fields.
Top
Remarks

When an item is added to this collection it is given a timestamp. The items in the collection are periodically checked, if they have been in the collection for longer than ExpireMilliseconds then they are removed.

This class is disposable. However, Dispose() just clears the collection. Clearing the collection releases all hooks, so it is kind-of permissible to not dispose of these objects - once the last item in the collection expires the class will automatically unhook itself and become eligible for finalising (if there are no strong references to it). However it is better if you can dispose of it when you are finished with it.

See Also