PageAsyncTask Constructors
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the PageAsyncTask class.
Overloads
PageAsyncTask(Func<CancellationToken,Task>) |
Initializes a new instance of the PageAsyncTask class using an event handler that enables the task to be canceled. |
PageAsyncTask(Func<Task>) |
Initializes a new instance of the PageAsyncTask class using an event handler that enables the task to be handled. |
PageAsyncTask(BeginEventHandler, EndEventHandler, EndEventHandler, Object) |
Initializes a new instance of the PageAsyncTask class using the default value for executing in parallel. |
PageAsyncTask(BeginEventHandler, EndEventHandler, EndEventHandler, Object, Boolean) |
Initializes a new instance of the PageAsyncTask class using the specified value for executing in parallel. |
PageAsyncTask(Func<CancellationToken,Task>)
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))
Parameters
- handler
- Func<CancellationToken,Task>
An event handler.
Remarks
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 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. When the AsyncTimeout value has been reached, the CancellationToken object will be signaled. The CancellationToken
parameter must be passed to any asynchronous APIs that are called by your implementation of the TaskEventHandler class.
Applies to
PageAsyncTask(Func<Task>)
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))
Parameters
Applies to
PageAsyncTask(BeginEventHandler, EndEventHandler, EndEventHandler, Object)
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)
Parameters
- 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.
Exceptions
The beginHandler
parameter or endHandler
parameter is not specified.
Remarks
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.
Applies to
PageAsyncTask(BeginEventHandler, EndEventHandler, EndEventHandler, Object, Boolean)
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)
Parameters
- 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.
Exceptions
The beginHandler
parameter or endHandler
parameter is not specified.
Examples
The following code example creates three asynchronous tasks that are processed in parallel to each other. 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)
Remarks
This implementation of the constructor allows you to set whether the asynchronous task will be processed in parallel with other tasks on the page.