Skip to content

ConcurrentList

huggins edited this page Apr 10, 2025 · 2 revisions

Concurrent List

Houses functionality to implement thread safe concurrent lists. Utilized in the UDPReceiverMulti class.

public class ConcurrentList<T> 
    : IList<T>, IDisposable

Includes

Back to Top


Members

Access Type Name Description
Private readonly List<T> _list The list to house entries.
Private readonly ReaderWriterLockSlim _lock The lock to verify the list is not access by multiple threads simultaneously.
Public int Count The number of entries contained in the list.
Public bool IsReadOnly Whether or not the list is read only.

Back to Top


Constructors

Access Name Description
Public ConcurrentList() Default constructor
Public ConcurrentList(int capacity) Initializes a concurrent list with the specified capacity.
Public ConcurrentList(IEnumerable<T> items) Initializes a concurrent list with the specified items.

Destructors

Name Description
~ConcurrentList() Default destructor

Functions

Access Return Name Description
Public void Add(T item) Adds a new entry into the list.
Public void Clear() Clears all entries from the list.
Public bool Contains(T item) Gets whether or not the list contains the given item.
Public void CopyTo(T[] array, int arrayIndex) Copies the list to the given array, starting at the given array index.
Public void Dispose() Public function to release all resources used by the _lock variable. Calls the private Dispose function.
Private void Dispose(bool disposing) Private function to release all resources used by the _lock variable.
Public IEnumerator<T> GetEnumerator() Returns an enumerator that iterates through the list.
IEnumerator IEnumerable.GetEnumerator() Returns an enumerator that iterates through the list.
Public int IndexOf(T item) Gets the index of the given item in the list.
Public void Insert(int index, T item) Inserts the given item into the specified index of the list.
Public bool Remove(T item) Removes the given item from the list.
Public void RemoveAt(int index) Removes the item from the list at the given location.

Back to Top


Details

_list

private readonly List<T> _list

The list to house entries.

Back to Top


_lock

private readonly ReaderWriterLockSlim _lock

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

Back to Top


Count

public int Count

The numer of entries contained in the list.

Back to Top


IsReadOnly

public bool IsReadOnly

Whether or not the list is read only.

Back to Top


ConcurrentList

ConcurrentList()

Default constructor.

Back to Top


ConcurrentList

ConcurrentList
(
	int Capacity
)

Initializes a concurrent list with the specified capacity.

Parameter Description
Capacity The capacity to initialize the list with.

Back to Top


ConcurrentList

ConcurrentList
(
	IEnumerable<T> items
)

Initializes a concurrent list with the specified items.

Parameter Description
items The items to intitialize the list with.

Back to Top


~ConcurrentList

~ConcurrentList()

Default destructor.

Back to Top


Add

public void Add
(
    T item
)

Adds a new entry into the list.

Parameter Description
item The item to add to the list.

Back to Top


Clear

public void Clear()

Clears all entries from the list.

Back to Top


Contains

public bool Contains
(
    T item
)

Gets whether or not the list contains the given item.

Parameter Description
item The item to search for in the list.
Returns
Whether or not the item is contained in the list.

Back to Top


CopyTo

public void CopyTo
(
    T[] array,
    int arrayIndex
)

Copies the list to the given array, starting at the given array index.

Parameter Description
array The array to copy the list items to.
arrayIndex The index of the array to begin copying at.

Back to Top


Dispose

public void Dispose()

Public function to release all resources used by the _lock variable. Calls the private Dispose function.

Back to Top


Dispose

public void Dispose
(
    bool disposing
)

Adds a new entry into the list.

Parameter Description
disposing Whether or not the common language runtime will call the finalizer for the specified object.

Back to Top


GetEnumerator

public IEnumerator<T> GetEnumerator()

Returns an enumerator that iterates through the list.

Back to Top


IEnumerable.GetEnumerator

IEnumerator IEnumerable.GetEnumerator()

Returns an enumerator that iterates through the list.

Back to Top


IndexOf

public int IndexOf
(
    T item
)

Gets the index of the given item in the list.

Parameter Description
item The item to get the index of in the list.
Returns
The location of the item in the list. Returns -1 if not found.

Back to Top


Insert

public void Insert
(
    int index, 
    T item
)

Inserts the given item into the specified index of the list.

Parameter Description
index The location in the list to insert the item at.
item The item to add to the list.

Back to Top


Remove

public bool Remove
(
    T item
)

Removes the given item from the list.

Parameter Description
item The item to remove from the list.
Returns
Whether or not an item was removed from the list.

Back to Top


RemoveAt

public void RemoveAt
(
    int index
)

Removes the item from the list at the given location.

Parameter Description
index The location to remove an item from in the list.

Back to Top


Clone this wiki locally