//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//------------------------------------------------------------------------------
namespace System.Web {
using System;
using System.Runtime.ExceptionServices;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Util;
// Provides an abstraction around the different SynchronizationContext-derived types that the
// ASP.NET runtime might use. Consumers can target this abstraction rather than coding against
// the various concrete types directly.
internal abstract class AspNetSynchronizationContextBase : SynchronizationContext {
private AllowAsyncOperationsBlockDisposable _allowAsyncOperationsBlockDisposable;
internal abstract bool AllowAsyncDuringSyncStages { get; set; }
internal abstract bool Enabled { get; }
internal Exception Error {
get {
ExceptionDispatchInfo dispatchInfo = ExceptionDispatchInfo;
return (dispatchInfo != null) ? dispatchInfo.SourceException : null;
}
}
internal abstract ExceptionDispatchInfo ExceptionDispatchInfo { get; }
internal abstract int PendingOperationsCount { get; }
internal abstract void ClearError();
internal abstract void Disable();
internal abstract void Enable();
internal abstract bool PendingCompletion(WaitCallback callback);
// A helper method which provides a Task-based wrapper around the PendingCompletion method.
// NOTE: The caller should verify that there are never outstanding calls to PendingCompletion
// or to WaitForPendingOperationsAsync, since each call replaces the continuation that will
// be invoked.
internal Task WaitForPendingOperationsAsync() {
TaskCompletionSource