2using System.Threading.Tasks;
23 semaphores.Removed += Semaphores_Removed;
30 return Task.CompletedTask;
41 semaphores[Key] = Result;
54 public static async Task<Semaphore>
BeginRead(
string Key)
68 return GetSemaphore(Key).
EndRead();
91 public static async Task<Semaphore>
BeginWrite(
string Key)
105 return GetSemaphore(Key).
EndWrite();
141 bool OnlyIfWaitingTasks)
143 if (MillisecondsThreshold <= 0)
144 throw new ArgumentOutOfRangeException(
"MilliSecondsThreshold must be greater than zero.", nameof(MillisecondsThreshold));
152 if (OnlyIfWaitingTasks && Obj.
QueueSize == 0)
159 return Result.ToArray();
Implements an in-memory cache.
Event arguments for cache item removal events.
ValueType Value
Value of item that was removed.
A chunked list is a linked list of chunks of objects of type T .
Represents an object that allows single concurrent writers but multiple concurrent readers....
virtual async Task< bool > TryBeginRead(int Timeout)
Waits, at most Timeout milliseconds, until object ready for reading. Each successful call to TryBegi...
virtual Task EndWrite()
Ends a writing session of the object. Must be called once for each call to BeginWrite or successful c...
double MillisecondsLocked
Number of milliseconds the object has been locked.
int QueueSize
Number of tasks waiting.
virtual async Task< bool > TryBeginWrite(int Timeout)
Waits, at most Timeout milliseconds, until object ready for writing. Each successful call to TryBegi...
virtual async Task BeginWrite()
Waits until object ready for writing. Each call to BeginWrite must be followed by exactly one call to...
virtual Task< int > EndRead()
Ends a reading session of the object. Must be called once for each call to BeginRead or successful ca...
virtual async Task< int > BeginRead()
Waits until object ready for reading. Each call to BeginRead must be followed by exactly one call to ...
Represents a named semaphore, i.e. an object, identified by a name, that allows single concurrent wri...
Static class of application-wide semaphores that can be used to order access to editable objects.
static MultiReadSingleWriteObject[] FindLockedObjects(int MillisecondsThreshold, bool OnlyIfWaitingTasks)
Returns an array of objects that have been locked for more time than the specified threshold.
static MultiReadSingleWriteObject[] FindLockedObjects(int MillisecondsThreshold)
Returns an array of objects that have been locked for more time than the specified threshold.
static Task< bool > TryBeginRead(string Key, int Timeout)
Waits, at most Timeout milliseconds, until the semaphore identified by Key is ready for reading....
static async Task< Semaphore > BeginRead(string Key)
Waits until the semaphore identified by Key is ready for reading. Each call to BeginRead must be fol...
static Task< bool > TryBeginWrite(string Key, int Timeout)
Waits, at most Timeout milliseconds, until the semaphore identified by Key is ready for writing....
static Task EndRead(string Key)
Ends a reading session of the semaphore identified by Key . Must be called once for each call to Begi...
static Task EndWrite(string Key)
Ends a writing session of the semaphore identified by Key . Must be called once for each call to Begi...
static async Task< Semaphore > BeginWrite(string Key)
Waits until the semaphore identified by Key is ready for writing. Each call to BeginWrite must be fo...