C# Класс SimpleHelpers.NamedLock

Synchronization helper: a static lock collection associated with a key. NamedLock manages the lifetime of critical sections that can be accessed by a key (name) throughout the application. It also have some helper methods to allow a maximum wait time (timeout) to aquire the lock and safelly release it. Note: this nuget package contains c# source code and depends on System.Collections.Concurrent introduced in .Net 4.0.
Наследование: IDisposable
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
CreateAndEnter ( string key ) : NamedLock

Creates a new instance and tries to aquire a lock.

CreateAndEnter ( string key, System.TimeSpan waitTimeout ) : NamedLock

Creates a new instance and tries to aquire a lock.

CreateAndEnter ( string key, int waitTimeoutMilliseconds ) : NamedLock

Creates a new instance and tries to aquire a lock.

Dispose ( ) : void

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. Releases aquired lock and related resources.

Enter ( ) : bool

Tries to aquire a lock.

Enter ( System.TimeSpan waitTimeout ) : bool

Tries to aquire a lock respecting the specified timeout.

Enter ( int waitTimeoutMilliseconds ) : bool

Tries to aquire a lock respecting the specified timeout.

Exit ( ) : bool

Releases the lock if it was already aquired. Called also at "Dispose".

NamedLock ( string key ) : System

Initializes a new instance of the NamedLock class.

Приватные методы

Метод Описание
GetOrAdd ( string key ) : object
LockFactory ( string key ) : CountedLock
ReleaseOrRemove ( string key ) : void

Описание методов

CreateAndEnter() публичный статический Метод

Creates a new instance and tries to aquire a lock.
public static CreateAndEnter ( string key ) : NamedLock
key string The named lock key.
Результат NamedLock

CreateAndEnter() публичный статический Метод

Creates a new instance and tries to aquire a lock.
public static CreateAndEnter ( string key, System.TimeSpan waitTimeout ) : NamedLock
key string The named lock key.
waitTimeout System.TimeSpan The wait timeout.
Результат NamedLock

CreateAndEnter() публичный статический Метод

Creates a new instance and tries to aquire a lock.
public static CreateAndEnter ( string key, int waitTimeoutMilliseconds ) : NamedLock
key string The named lock key.
waitTimeoutMilliseconds int The wait timeout milliseconds.
Результат NamedLock

Dispose() публичный Метод

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. Releases aquired lock and related resources.
public Dispose ( ) : void
Результат void

Enter() публичный Метод

Tries to aquire a lock.
public Enter ( ) : bool
Результат bool

Enter() публичный Метод

Tries to aquire a lock respecting the specified timeout.
public Enter ( System.TimeSpan waitTimeout ) : bool
waitTimeout System.TimeSpan The wait timeout.
Результат bool

Enter() публичный Метод

Tries to aquire a lock respecting the specified timeout.
public Enter ( int waitTimeoutMilliseconds ) : bool
waitTimeoutMilliseconds int The wait timeout milliseconds.
Результат bool

Exit() публичный Метод

Releases the lock if it was already aquired. Called also at "Dispose".
public Exit ( ) : bool
Результат bool

NamedLock() публичный Метод

Initializes a new instance of the NamedLock class.
public NamedLock ( string key ) : System
key string The named lock key.
Результат System