mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-19 01:31:17 -10:00
Adding reference source for System.Data System.Data.DataSetExtensions System.Data.Entity System.Data.Entity.Design System.Data.Linq System.Data.SqlXml System.ServiceModel System.ServiceModel.Activation System.ServiceModel.Activities System.ServiceModel.Channels System.ServiceModel.Discovery System.ServiceModel.Internals System.ServiceModel.Routing System.ServiceModel.WasHosting System.ServiceModel.Web System.Web System.Web.ApplicationServices System.Web.DynamicData System.Web.Entity System.Web.Entity.Design System.Web.Extensions System.Web.Mobile System.Web.Routing System.Web.Services System.Xml System.Xml.Linq
91 lines
3.9 KiB
C#
91 lines
3.9 KiB
C#
//------------------------------------------------------------------------------
|
|
// <copyright file="PageAsyncTask.cs" company="Microsoft">
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// </copyright>
|
|
//------------------------------------------------------------------------------
|
|
|
|
namespace System.Web.UI {
|
|
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using System.Web.Util;
|
|
|
|
// Public class to serve as an interface between ASP.NET's synchronization systems and the user code to be executed asynchronously
|
|
|
|
public sealed class PageAsyncTask {
|
|
|
|
// APM
|
|
public PageAsyncTask(BeginEventHandler beginHandler, EndEventHandler endHandler, EndEventHandler timeoutHandler, Object state)
|
|
: this(beginHandler, endHandler, timeoutHandler, state, executeInParallel: false) {
|
|
}
|
|
|
|
// APM
|
|
public PageAsyncTask(BeginEventHandler beginHandler, EndEventHandler endHandler, EndEventHandler timeoutHandler, Object state, bool executeInParallel)
|
|
: this(beginHandler, endHandler, timeoutHandler, state, executeInParallel, currentMode: SynchronizationContextUtil.CurrentMode) {
|
|
}
|
|
|
|
// APM
|
|
internal PageAsyncTask(BeginEventHandler beginHandler, EndEventHandler endHandler, EndEventHandler timeoutHandler, Object state, bool executeInParallel, SynchronizationContextMode currentMode) {
|
|
if (beginHandler == null) {
|
|
throw new ArgumentNullException("beginHandler");
|
|
}
|
|
if (endHandler == null) {
|
|
throw new ArgumentNullException("endHandler");
|
|
}
|
|
|
|
// Only the legacy PageAsyncTaskManager supports timing out APM methods or executing them in parallel
|
|
if (timeoutHandler != null || executeInParallel) {
|
|
SynchronizationContextUtil.ValidateMode(currentMode, requiredMode: SynchronizationContextMode.Legacy, specificErrorMessage: SR.SynchronizationContextUtil_PageAsyncTaskTimeoutHandlerParallelNotCompatible);
|
|
}
|
|
|
|
BeginHandler = beginHandler;
|
|
EndHandler = endHandler;
|
|
TimeoutHandler = timeoutHandler;
|
|
State = state;
|
|
ExecuteInParallel = executeInParallel;
|
|
}
|
|
|
|
// TAP
|
|
public PageAsyncTask(Func<Task> handler)
|
|
: this(WrapParameterlessTaskHandler(handler)) {
|
|
}
|
|
|
|
public PageAsyncTask(Func<CancellationToken, Task> handler)
|
|
: this(handler, currentMode: SynchronizationContextUtil.CurrentMode) {
|
|
}
|
|
|
|
// TAP
|
|
internal PageAsyncTask(Func<CancellationToken, Task> handler, SynchronizationContextMode currentMode) {
|
|
if (handler == null) {
|
|
throw new ArgumentNullException("handler");
|
|
}
|
|
|
|
// The legacy PageAsyncTaskManager doesn't support TAP methods
|
|
SynchronizationContextUtil.ValidateMode(currentMode, requiredMode: SynchronizationContextMode.Normal, specificErrorMessage: SR.SynchronizationContextUtil_TaskReturningPageAsyncMethodsNotCompatible);
|
|
|
|
TaskHandler = handler;
|
|
}
|
|
|
|
#region Legacy properties
|
|
// These properties were present in the original PageAsyncTask type, so they must remain in this new type, even if they're unused.
|
|
|
|
public BeginEventHandler BeginHandler { get; private set; }
|
|
public EndEventHandler EndHandler { get; private set; }
|
|
public bool ExecuteInParallel { get; private set; }
|
|
public object State { get; private set; }
|
|
public EndEventHandler TimeoutHandler { get; private set; }
|
|
#endregion
|
|
|
|
// For TAP
|
|
internal Func<CancellationToken, Task> TaskHandler { get; private set; }
|
|
|
|
private static Func<CancellationToken, Task> WrapParameterlessTaskHandler(Func<Task> handler) {
|
|
return (handler != null)
|
|
? (Func<CancellationToken, Task>)(_ => handler())
|
|
: null;
|
|
}
|
|
|
|
}
|
|
}
|