SynchronizedCollection

Ecng.Collections

Represents a thread-safe collection that provides synchronization for its operations.

Inherits: BaseCollection<T, T>

Implements: ISynchronizedCollection<T>, ISynchronizedCollection, ISynchronizable, ICollection<T>, IEnumerable<T>, IEnumerable

Constructors

SynchronizedCollection
protected SynchronizedCollection(TCollection innerCollection)
synchronizedCollection = SynchronizedCollection(innerCollection)

Represents a thread-safe collection that provides synchronization for its operations.

Properties

Count
public override int Count { get; }
value = synchronizedCollection.Count

Gets the number of elements contained in the collection.

Item
public override TItem Item { get; set; }
value = synchronizedCollection.Item
synchronizedCollection.Item = value

Gets or sets the element at the specified index.

index
The zero-based index of the element to get or set.

Returns: The element at the specified index.

SyncRoot
public Lock SyncRoot { get; }
value = synchronizedCollection.SyncRoot

Gets the synchronization root object used to synchronize access to the collection.

Methods

Add
public override void Add(TItem item)
synchronizedCollection.Add(item)

Adds an item to the collection.

item
The item to add to the collection.
Clear
public override void Clear()
synchronizedCollection.Clear()

Removes all items from the collection.

Contains
public override bool Contains(TItem item)
result = synchronizedCollection.Contains(item)

Determines whether the collection contains a specific item.

item
The item to locate in the collection.

Returns: true if the item is found in the collection; otherwise, false.

EnterScope
public Scope EnterScope()
result = synchronizedCollection.EnterScope()

Enters a synchronized scope for thread-safe operations on the collection.

Returns: A Scope that represents the synchronized scope.

GetEnumerator
public override IEnumerator<TItem> GetEnumerator()
result = synchronizedCollection.GetEnumerator()

Returns an enumerator that iterates through the collection.

Returns: An enumerator that can be used to iterate through the collection.

IndexOf
public override int IndexOf(TItem item)
result = synchronizedCollection.IndexOf(item)

Determines the index of a specific item in the collection.

item
The item to locate in the collection.

Returns: The index of the item if found in the collection; otherwise, -1.

Insert
public override void Insert(int index, TItem item)
synchronizedCollection.Insert(index, item)

Inserts an item into the collection at the specified index.

index
The zero-based index at which the item should be inserted.
item
The item to insert into the collection.
OnIndexOf
protected abstract int OnIndexOf(TItem item)
result = synchronizedCollection.OnIndexOf(item)

When overridden in a derived class, determines the index of a specific item in the collection.

item
The item to locate in the collection.

Returns: The index of the item if found in the collection; otherwise, -1.

Remove
public override bool Remove(TItem item)
result = synchronizedCollection.Remove(item)

Removes the first occurrence of a specific item from the collection.

item
The item to remove from the collection.

Returns: true if the item was successfully removed; otherwise, false.

RemoveAt
public override void RemoveAt(int index)
synchronizedCollection.RemoveAt(index)

Removes the item at the specified index.

index
The zero-based index of the item to remove.