예제 #1
0
        private void AcquireTakeCancellationHandler(object _acquireNode, bool canceling)
        {
            LinkedListNode <AsyncTake> acquireNode = (LinkedListNode <AsyncTake>)_acquireNode;
            AsyncTake acquire = acquireNode.Value;

            if (acquire.TryLock())
            {
                // To access shared mutable state we must acquire the lock
                lock (theLock)
                {
                    asyncTakes.Remove(acquireNode);
                }

                // Release the resources associated with the async acquire.
                acquire.Dispose(canceling);

                // Complete the TaskCompletionSource to RanToCompletion (timeout)
                // or Canceled final state.
                if (canceling)
                {
                    acquire.SetCanceled();
                }
                else
                {
                    acquire.SetResult(default);
예제 #2
0
        private void TakeCancellationHandler(object request, bool canceling)
        {
            LinkedListNode <AsyncTake> node = (LinkedListNode <AsyncTake>)request;
            AsyncTake take = node.Value;

            if (take.TryLock())
            {
                lock (_lock) {
                    if (node.List != null)
                    {
                        _asyncTakes.Remove(node);
                    }
                }

                take.Dispose();

                if (canceling)
                {
                    take.SetCanceled();
                }
                else
                {
                    take.SetResult(default);