You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
90
mcs/class/referencesource/System.Web/UI/PageAsyncTask.cs
Normal file
90
mcs/class/referencesource/System.Web/UI/PageAsyncTask.cs
Normal file
@ -0,0 +1,90 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user