Skip to content

ConcurrentEnumerator

huggins edited this page May 10, 2023 · 1 revision

Concurrent Enumerator

Houses functionality to implement thread safe concurrent enumerators. Utilized in the ConcurrentList class.

public class ConcurrentEnumerator<T> 
    : IEnumerator<T>

Includes

Back to Top


Members

Access Type Name Description
Private readonly List<T> _inner The enumerator that is thread safe.
Private readonly ReaderWriterLockSlim _lock The lock to verify the enumerator is not access by multiple threads simultaneously.
Public T Current Gets the element in the collection at the current position of the enumerator.
object IEnumerator.Current Gets the element in the collection at the current position of the enumerator.

Back to Top


Constructors

Access Name Description
Public ConcurrentEnumerator(IEnumerable<T> inner, ReaderWriterLockSlim @lock) Initializes a concurrent enumerator for the specified list.

Functions

Access Return Name Description
Public void Dispose() Releases all resources used by the _lock variable.
Public bool MoveNext() Advances the enumerator to the next element of the collection.
Public void Reset() Sets the enumerator to its initial position, which is before the first element in the collection.

Back to Top


Details

_inner

private readonly IEnumerator<T> _inner

The enumerator that is thread safe.

Back to Top


_lock

private readonly ReaderWriterLockSlim _lock

The lock to verify the list is not access by multiple threads simultaneously.

Back to Top


Current

public T Current

Gets the element in the collection at the current position of the enumerator.

Back to Top


IEnumerator.Current

object IEnumerator.Current

Gets the element in the collection at the current position of the enumerator.

Back to Top


ConcurrentEnumerator

ConcurrentEnumerator()

Initializes a concurrent enumerator for the specified list.

Back to Top


Dispose

public void Dispose()

Releases all resources used by the _lock variable.

Back to Top


MoveNext

public bool MoveNext()

Advances the enumerator to the next element of the collection.

Returns
Whether or not the enumerator was successfully advanced to the next element.

Back to Top


Reset

public void Reset()

Sets the enumerator to its initial position, which is before the first element in the collection.

Back to Top