示例#1
0
    /**
     * Try to cancel an async put request.
     */
    private void PutCancellationHandler(object _putNode, bool canceling)
    {
        LinkedListNode <AsyncPut> putNode = (LinkedListNode <AsyncPut>)_putNode;
        AsyncPut put = null;

        lock (theLock) {
            if (!putNode.Value.done)
            {
                asyncPuts.Remove(putNode);
                put      = putNode.Value;
                put.done = true;
            }
        }
        if (put != null)
        {
            // Dispose resources associated with this async put request.
            put.Dispose(canceling);

            // Complete the underlying task properly.
            if (canceling)
            {
                put.SetCanceled();
            }
            else
            {
                put.SetResult(false);
            }
        }
    }
示例#2
0
    /**
     * Try to cancel an asynchronous put represented by its task.
     */
    private bool CancelPutByTask(Task <bool> putTask)
    {
        AsyncPut put = null;

        lock (theLock) {
            foreach (AsyncPut _put in asyncPuts)
            {
                if (_put.Task == putTask)
                {
                    put = _put;
                    asyncPuts.Remove(_put);
                    break;
                }
            }
        }
        if (put != null)
        {
            put.Dispose();
            put.SetCanceled();
        }
        return(put != null);
    }