Jo Shields 3c1f479b9d Imported Upstream version 4.0.0~alpha1
Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
2015-04-07 09:35:12 +01:00

55 lines
1.6 KiB
C#

//------------------------------------------------------------------------------
// <copyright file="TaskWrapperAsyncResult.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* Wraps a Task class, optionally overriding the State object (since the Task Asynchronous Pattern doesn't normally use them).
*
* Copyright (c) 2010 Microsoft Corporation
*/
namespace System.Web {
using System;
using System.Threading;
using System.Threading.Tasks;
internal sealed class TaskWrapperAsyncResult : IAsyncResult {
private bool _forceCompletedSynchronously;
internal TaskWrapperAsyncResult(Task task, object asyncState) {
Task = task;
AsyncState = asyncState;
}
public object AsyncState {
get;
private set;
}
public WaitHandle AsyncWaitHandle {
get { return ((IAsyncResult)Task).AsyncWaitHandle; }
}
public bool CompletedSynchronously {
get { return _forceCompletedSynchronously || ((IAsyncResult)Task).CompletedSynchronously; }
}
public bool IsCompleted {
get { return ((IAsyncResult)Task).IsCompleted; }
}
internal Task Task {
get;
private set;
}
internal void ForceCompletedSynchronously() {
_forceCompletedSynchronously = true;
}
}
}