/// <summary>
 /// Creates the LockedResource.  Until you actually return it to the ultimate consumer in one of the <see cref="Lock()"/> or <see cref="SpinLock()"/>
 /// methods (which are annotated with <see cref="UsingMandatoryAttribute"/>, guaranteeing disposal) it is YOUR responsiblity to make sure
 /// that the item is disposed IN ANY PATH THAT DOES NOT RESULT IN THE USER GETTING THE LOCKED RESOURCE REQUESTED.  This include exceptions,
 /// short-circuited returns, etc.
 /// </summary>
 /// <param name="timeout">How long should be wait.  If null, wait forever</param>
 /// <param name="token">A cancellation token that can be used to cancel attempting to obtain the resource.</param>
 /// <returns>A locked vault mutable resource</returns>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="timeout"/> was not-null but was not positive</exception>
 /// <exception cref="TimeoutException">operation not completed in time (should be handled by user not by me or you ... except, see above, we need
 /// to dispose the resource ourselves if we've obtained it ... before rethrowing)</exception>
 /// <exception cref="OperationCanceledException">the operation was cancelled and the cancellation was received via <paramref name="token"/>.
 /// The user should handle this, not you or me (except, if we obtained the resource we need to dispose it before rethrowing).</exception>
 /// <exception cref="LockAlreadyHeldThreadException">The thread you are attempting to obtain a lock on has already obtained the lock.</exception>
 protected LockedMonVaultMutableResource <MutableResourceMonitorVault <T>, T> PerformLock(TimeSpan?timeout, CancellationToken token)
 {
     using (var ilr = ExecuteGetInternalLockedResource(timeout, token))
     {
         return(LockedMonVaultMutableResource <MutableResourceMonitorVault <T>, T> .CreateLockedResource(this, ilr.Release()));
     }
 }
 /// <summary>
 /// Try to obtain a locked resource using a simple Monitor.Enter with no timeout and no cancellation token support
 /// This method may deadlock
 /// </summary>
 /// <returns>A locked vault mutable resource</returns>
 /// <exception cref="LockAlreadyHeldThreadException">The thread you are attempting to obtain a lock on has already obtained the lock.</exception>
 protected LockedMonVaultMutableResource <MutableResourceMonitorVault <T>, T> PerformLockBlockForever()
 {
     using (var ilr = ExecuteGetInternalLockedResourceBlockForever())
     {
         return(LockedMonVaultMutableResource <MutableResourceMonitorVault <T>, T> .CreateLockedResource(this, ilr.Release()));
     }
 }
Exemplo n.º 3
0
 internal static LockedMonitorStringBuilder CreateLockedResource(
     LockedMonVaultMutableResource <MutableResourceMonitorVault <StringBuilder>, StringBuilder> me)
 => new LockedMonitorStringBuilder(me);