PageAsyncTask 构造函数
定义
初始化 PageAsyncTask 类的新实例。Initializes a new instance of the PageAsyncTask class.
重载
| PageAsyncTask(Func<CancellationToken,Task>) |
使用能取消任务的事件处理程序初始化 PageAsyncTask 类的新实例。Initializes a new instance of the PageAsyncTask class using an event handler that enables the task to be canceled. |
| PageAsyncTask(Func<Task>) |
使用能处理任务的事件处理程序初始化 PageAsyncTask 类的新实例。Initializes a new instance of the PageAsyncTask class using an event handler that enables the task to be handled. |
| PageAsyncTask(BeginEventHandler, EndEventHandler, EndEventHandler, Object) |
使用并行执行的默认值初始化 PageAsyncTask 类的新实例。Initializes a new instance of the PageAsyncTask class using the default value for executing in parallel. |
| PageAsyncTask(BeginEventHandler, EndEventHandler, EndEventHandler, Object, Boolean) |
使用并行执行的指定值初始化 PageAsyncTask 类的新实例。Initializes a new instance of the PageAsyncTask class using the specified value for executing in parallel. |
PageAsyncTask(Func<CancellationToken,Task>)
使用能取消任务的事件处理程序初始化 PageAsyncTask 类的新实例。Initializes a new instance of the PageAsyncTask class using an event handler that enables the task to be canceled.
public:
PageAsyncTask(Func<System::Threading::CancellationToken, System::Threading::Tasks::Task ^> ^ handler);
public PageAsyncTask (Func<System.Threading.CancellationToken,System.Threading.Tasks.Task> handler);
new System.Web.UI.PageAsyncTask : Func<System.Threading.CancellationToken, System.Threading.Tasks.Task> -> System.Web.UI.PageAsyncTask
Public Sub New (handler As Func(Of CancellationToken, Task))
参数
- handler
- Func<CancellationToken,Task>
事件处理程序。An event handler.
注解
此构造函数包装 TaskEventHandler 委托,以便 PageAsyncTask 对象可以基于 Task) 现有 ASP.NET Web 窗体异步页功能的对象来集成异步代码 (。This constructor wraps a TaskEventHandler delegate so that the PageAsyncTask object can integrate asynchronous code (based on Task objects) with the existing ASP.NET Web Forms asynchronous pages feature. ASP.NET 将根据网页 CancellationToken TaskEventHandler 指令中设置的属性,向传递给委托的对象发出信号 AsyncTimeout @ Page 。ASP.NET will signal the CancellationToken object that is passed to a TaskEventHandler delegate for cancellation based on the AsyncTimeout attribute set in the @ Page directive of the Web page. 达到此 AsyncTimeout 值时, CancellationToken 将终止对象。When the AsyncTimeout value has been reached, the CancellationToken object will be signaled. CancellationToken参数必须传递到由类的实现调用的任何异步 api TaskEventHandler 。The CancellationToken parameter must be passed to any asynchronous APIs that are called by your implementation of the TaskEventHandler class.
适用于
PageAsyncTask(Func<Task>)
使用能处理任务的事件处理程序初始化 PageAsyncTask 类的新实例。Initializes a new instance of the PageAsyncTask class using an event handler that enables the task to be handled.
public:
PageAsyncTask(Func<System::Threading::Tasks::Task ^> ^ handler);
public PageAsyncTask (Func<System.Threading.Tasks.Task> handler);
new System.Web.UI.PageAsyncTask : Func<System.Threading.Tasks.Task> -> System.Web.UI.PageAsyncTask
Public Sub New (handler As Func(Of Task))
参数
适用于
PageAsyncTask(BeginEventHandler, EndEventHandler, EndEventHandler, Object)
使用并行执行的默认值初始化 PageAsyncTask 类的新实例。Initializes a new instance of the PageAsyncTask class using the default value for executing in parallel.
public:
PageAsyncTask(System::Web::BeginEventHandler ^ beginHandler, System::Web::EndEventHandler ^ endHandler, System::Web::EndEventHandler ^ timeoutHandler, System::Object ^ state);
public PageAsyncTask (System.Web.BeginEventHandler beginHandler, System.Web.EndEventHandler endHandler, System.Web.EndEventHandler timeoutHandler, object state);
new System.Web.UI.PageAsyncTask : System.Web.BeginEventHandler * System.Web.EndEventHandler * System.Web.EndEventHandler * obj -> System.Web.UI.PageAsyncTask
Public Sub New (beginHandler As BeginEventHandler, endHandler As EndEventHandler, timeoutHandler As EndEventHandler, state As Object)
参数
- beginHandler
- BeginEventHandler
当异步任务开始时要调用的处理程序。The handler to call when beginning an asynchronous task.
- endHandler
- EndEventHandler
当任务在超时期内成功完成时要调用的处理程序。The handler to call when the task is completed successfully within the time-out period.
- timeoutHandler
- EndEventHandler
当任务未在超时期内成功完成时要调用的处理程序。The handler to call when the task is not completed successfully within the time-out period.
- state
- Object
表示任务状态的对象。The object that represents the state of the task.
例外
beginHandler 参数或 endHandler 参数未指定。The beginHandler parameter or endHandler parameter is not specified.
注解
此构造函数的实现将 ExecuteInParallel 属性设置为, false 以便不会与页面上的其他任务并行处理异步任务。This implementation of the constructor sets the ExecuteInParallel property to false so the asynchronous task is not processed in parallel with other tasks on the page.
适用于
PageAsyncTask(BeginEventHandler, EndEventHandler, EndEventHandler, Object, Boolean)
使用并行执行的指定值初始化 PageAsyncTask 类的新实例。Initializes a new instance of the PageAsyncTask class using the specified value for executing in parallel.
public:
PageAsyncTask(System::Web::BeginEventHandler ^ beginHandler, System::Web::EndEventHandler ^ endHandler, System::Web::EndEventHandler ^ timeoutHandler, System::Object ^ state, bool executeInParallel);
public PageAsyncTask (System.Web.BeginEventHandler beginHandler, System.Web.EndEventHandler endHandler, System.Web.EndEventHandler timeoutHandler, object state, bool executeInParallel);
new System.Web.UI.PageAsyncTask : System.Web.BeginEventHandler * System.Web.EndEventHandler * System.Web.EndEventHandler * obj * bool -> System.Web.UI.PageAsyncTask
Public Sub New (beginHandler As BeginEventHandler, endHandler As EndEventHandler, timeoutHandler As EndEventHandler, state As Object, executeInParallel As Boolean)
参数
- beginHandler
- BeginEventHandler
当异步任务开始时要调用的处理程序。The handler to call when beginning an asynchronous task.
- endHandler
- EndEventHandler
当任务在超时期内成功完成时要调用的处理程序。The handler to call when the task is completed successfully within the time-out period.
- timeoutHandler
- EndEventHandler
当任务未在超时期内成功完成时要调用的处理程序。The handler to call when the task is not completed successfully within the time-out period.
- state
- Object
表示任务状态的对象。The object that represents the state of the task.
- executeInParallel
- Boolean
指示任务能否与其他任务并行处理的值。The value that indicates whether the task can be processed in parallel with other tasks.
例外
beginHandler 参数或 endHandler 参数未指定。The beginHandler parameter or endHandler parameter is not specified.
示例
下面的代码示例创建三个相互并行处理的异步任务。The following code example creates three asynchronous tasks that are processed in parallel to each other. 此示例摘自类概述中的一个更大的示例 PageAsyncTask 。This example is part of a larger example found in the PageAsyncTask class overview.
PageAsyncTask asyncTask1 = new PageAsyncTask(slowTask1.OnBegin, slowTask1.OnEnd, slowTask1.OnTimeout, "Async1", true);
PageAsyncTask asyncTask2 = new PageAsyncTask(slowTask2.OnBegin, slowTask2.OnEnd, slowTask2.OnTimeout, "Async2", true);
PageAsyncTask asyncTask3 = new PageAsyncTask(slowTask3.OnBegin, slowTask3.OnEnd, slowTask3.OnTimeout, "Async3", true);
// Register the asynchronous task.
Page.RegisterAsyncTask(asyncTask1);
Page.RegisterAsyncTask(asyncTask2);
Page.RegisterAsyncTask(asyncTask3);
Dim asyncTask1 As New PageAsyncTask(AddressOf slowTask1.OnBegin, AddressOf slowTask1.OnEnd, AddressOf slowTask1.OnTimeout, "Async1", True)
Dim asyncTask2 As New PageAsyncTask(AddressOf slowTask2.OnBegin, AddressOf slowTask2.OnEnd, AddressOf slowTask2.OnTimeout, "Async2", True)
Dim asyncTask3 As New PageAsyncTask(AddressOf slowTask3.OnBegin, AddressOf slowTask3.OnEnd, AddressOf slowTask3.OnTimeout, "Async3", True)
' Register the asynchronous task.
Page.RegisterAsyncTask(asyncTask1)
Page.RegisterAsyncTask(asyncTask2)
Page.RegisterAsyncTask(asyncTask3)
注解
此构造函数的实现允许您设置异步任务是否将与页面上的其他任务并行处理。This implementation of the constructor allows you to set whether the asynchronous task will be processed in parallel with other tasks on the page.