public Task<Token> AcquireAsync() { OwnerToken nextOwner = new OwnerToken(); Task<Token> task = nextOwner.Task; lock (this.nextOwners) { if (this.owner == null) { this.owner = nextOwner; nextOwner.Complete(); } else { this.nextOwners.Enqueue(nextOwner); } } return task; }
public Task <Token> AcquireAsync() { OwnerToken nextOwner = new OwnerToken(); Task <Token> task = nextOwner.Task; lock (this.nextOwners) { if (this.owner == null) { this.owner = nextOwner; nextOwner.Complete(); } else { this.nextOwners.Enqueue(nextOwner); } } return(task); }
public void Release(Token token) { OwnerToken nextOwner = null; lock (this.nextOwners) { if (this.owner != token) { throw new InvalidOperationException("The token is not valid."); } this.owner = null; if (this.nextOwners.Count > 0) { nextOwner = this.nextOwners.Dequeue(); this.owner = nextOwner; } } if (nextOwner != null) { nextOwner.Complete(); } }