-
Notifications
You must be signed in to change notification settings - Fork 6
ConcurrentEnumerator
huggins edited this page Apr 10, 2025
·
2 revisions
Houses functionality to implement thread safe concurrent enumerators. Utilized in the ConcurrentList class.
public class ConcurrentEnumerator<T>
: IEnumerator<T>| 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. |
| Access | Name | Description |
|---|---|---|
| Public | ConcurrentEnumerator(IEnumerable<T> inner, ReaderWriterLockSlim @lock) | Initializes a concurrent enumerator for the specified list. |
| 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. |
private readonly IEnumerator<T> _innerThe enumerator that is thread safe.
private readonly ReaderWriterLockSlim _lockThe lock to verify the list is not access by multiple threads simultaneously.
public T CurrentGets the element in the collection at the current position of the enumerator.
object IEnumerator.CurrentGets the element in the collection at the current position of the enumerator.
ConcurrentEnumerator()Initializes a concurrent enumerator for the specified list.
public void Dispose()Releases all resources used by the _lock variable.
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. |
public void Reset()Sets the enumerator to its initial position, which is before the first element in the collection.