コード例 #1
0
 /// <summary>
 /// Acquires the lock synchronously, failing with <see cref="TimeoutException"/> if the wait times out
 /// <code>
 ///     using (myLock.Acquire(...))
 ///     {
 ///         // we have the lock
 ///     }
 ///     // dispose releases the lock
 /// </code>
 /// </summary>
 /// <param name="timeout">How long to wait before giving up on acquiring the lock. Defaults to <see cref="Timeout.InfiniteTimeSpan"/></param>
 /// <param name="cancellationToken">Specifies a token by which the wait can be canceled</param>
 /// <returns>An <see cref="IDisposable"/> "handle" which can be used to release the lock</returns>
 public IDisposable Acquire(TimeSpan?timeout = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(DistributedLockHelpers.Acquire(this, timeout, cancellationToken));
 }