Method UnsafeTryPerformLockedOperation
UnsafeTryPerformLockedOperation<TState>(TState, Action<WeakList<T>, TState>)
Runs the specified operation while holding the list's internal lock if the lock can be acquired immediately, so that multiple operations can be performed without other threads modifying the list in between them.
Declaration
public bool UnsafeTryPerformLockedOperation<TState>(TState state, Action<WeakList<T>, TState> operation) where TState : allows ref struct
Parameters
| Type | Name | Description |
|---|---|---|
| TState | state | A state value to pass to the operation. |
| Action<WeakList<T>, TState> | operation | The operation to run. It receives the list and the state value. |
Returns
| Type | Description |
|---|---|
| bool | true if the operation was run; false if the lock could not be acquired immediately or the list has been disposed. |
Type Parameters
| Name | Description |
|---|---|
| TState |
Remarks
The lock is also required by the finalizer thread to remove nodes whose values have been garbage collected, so holding it for more than a short time delays finalization of every object in the process. Keep operations short. For long-running compound operations, use your own lock and account for nodes being removed from the list concurrently.
Disposing the list from within operation releases the lock immediately, so any code that runs in the operation after the dispose
call is no longer protected by it.