• Performance
  • API Documentation
  • Source Code
Show / Hide Table of Contents
  • InSync
    • AsyncSynchronized
    • AsyncSynchronized<T>
    • GuardedValue<T>
    • IAsyncSynchronized<T>
    • IBareAsyncLock
    • IBareAsyncLock<T>
    • IBareLock
    • IBareLock<T>
    • ISynchronized<T>
    • LockException
    • MultiSync
    • ReaderSynchronized<TRead>
    • ReaderWriterSynchronized<T>
    • ReaderWriterSynchronized<TWrite, TRead>
    • ReaderWriterSynchronizedFactory
    • Synchronized
    • Synchronized<T>
    • TimingMethod
    • UnlockException
    • UpgradeableReaderSynchronized<TRead>
    • ValueContainer<T>

Interface ISynchronized<T>

Allows its protected object to be accessed only after a synchronization begins. Its methods automatically complete synchronizations or provide some means to do so. They properly handle exceptions thrown by starts of synchronization or users' operations.

Asynchronous operations are not supported. The protected object is non-null.

Namespace: InSync
Assembly: InSync.dll
Syntax
public interface ISynchronized<T>
    where T : class
Type Parameters
Name Description
T

The type of the protected object.

Methods

Lock()

Locks and returns a guard to allow access of the protected object and unlocking.

Declaration
GuardedValue<T> Lock()
Returns
Type Description
GuardedValue<T>
Exceptions
Type Condition
LockException

TryLock()

Tries to lock and returns a guard to allow access of the protected object and unlocking. If the lock is not acquired, this method returns null immediately.

Declaration
GuardedValue<T> TryLock()
Returns
Type Description
GuardedValue<T>

Null if the lock is not acquired.

Exceptions
Type Condition
LockException

TryLock(Int32)

Tries to lock and returns a guard to allow access of the protected object and unlocking. If the lock is not acquired, this method returns null immediately.

Declaration
GuardedValue<T> TryLock(int millisecondsTimeout)
Parameters
Type Name Description
System.Int32 millisecondsTimeout

The number of milliseconds to wait, (-1) to wait indefinitely, or zero to test the state of the wait handle and return immediately.

Returns
Type Description
GuardedValue<T>

Null if the lock is not acquired.

Exceptions
Type Condition
LockException

TryLock(TimeSpan)

Tries to lock and returns a guard to allow access of the protected object and unlocking. If the lock is not acquired, this method returns null immediately.

Declaration
GuardedValue<T> TryLock(TimeSpan timeout)
Parameters
Type Name Description
TimeSpan timeout

A that represents the number of milliseconds to wait, a that represents -1 milliseconds to wait indefinitely, or a that represents 0 milliseconds to test the wait handle and return immediately.

Returns
Type Description
GuardedValue<T>

Null if the lock is not acquired.

Exceptions
Type Condition
LockException

TryWithLock(Action<T>)

Tries to lock and performs the action then unlocks. If the lock is not acquired, this method returns immediately. If the action throws an exception, the lock is released automatically.

Declaration
bool TryWithLock(Action<T> action)
Parameters
Type Name Description
Action<T> action

The protected object is supplied as the argument of the action

Returns
Type Description
System.Boolean

true the action is performed.

Exceptions
Type Condition
LockException
UnlockException

TryWithLock(Int32, Action<T>)

Tries to lock and performs the action then unlocks. If the lock is not acquired, this method returns immediately. If the action throws an exception, the lock is released automatically.

Declaration
bool TryWithLock(int millisecondsTimeout, Action<T> action)
Parameters
Type Name Description
System.Int32 millisecondsTimeout

The number of milliseconds to wait, (-1) to wait indefinitely, or zero to test the state of the wait handle and return immediately.

Action<T> action

The protected object is supplied as the argument of the action

Returns
Type Description
System.Boolean

true the action is performed.

Exceptions
Type Condition
LockException
UnlockException

TryWithLock(TimeSpan, Action<T>)

Tries to lock and performs the action then unlocks. If the lock is not acquired, this method returns immediately. If the action throws an exception, the lock is released automatically.

Declaration
bool TryWithLock(TimeSpan timeout, Action<T> action)
Parameters
Type Name Description
TimeSpan timeout

A that represents the number of milliseconds to wait, a that represents -1 milliseconds to wait indefinitely, or a that represents 0 milliseconds to test the wait handle and return immediately.

Action<T> action

The protected object is supplied as the argument of the action

Returns
Type Description
System.Boolean

true the action is performed.

Exceptions
Type Condition
LockException
UnlockException

WithLock(Action<T>)

Locks, performs the action then unlocks. If the action throws an exception, the lock is released automatically.

Declaration
void WithLock(Action<T> action)
Parameters
Type Name Description
Action<T> action

The protected object is supplied as the argument of the action

Exceptions
Type Condition
LockException
UnlockException

WithLock<TResult>(Func<T, TResult>)

Locks, call the function then unlocks. The returned value from the function is returned. If the function throws an exception, the lock is released automatically.

Declaration
TResult WithLock<TResult>(Func<T, TResult> func)
Parameters
Type Name Description
Func<T, TResult> func

The protected object is supplied as the argument of the function. The returned value is returned by this method.

Returns
Type Description
TResult

The returned value from the function.

Type Parameters
Name Description
TResult
Exceptions
Type Condition
LockException
UnlockException
In This Article
Back to top Generated by DocFX