PageAsyncTask Constructors

Definition

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.

C#
public PageAsyncTask(Func<System.Threading.CancellationToken,System.Threading.Tasks.Task> handler);

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

PageAsyncTask(Func<Task>)

Initializes a new instance of the PageAsyncTask class using an event handler that enables the task to be handled.

C#
public PageAsyncTask(Func<System.Threading.Tasks.Task> handler);

Parameters

handler
Func<Task>

An event handler.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

PageAsyncTask(BeginEventHandler, EndEventHandler, EndEventHandler, Object)

Initializes a new instance of the PageAsyncTask class using the default value for executing in parallel.

C#
public PageAsyncTask(System.Web.BeginEventHandler beginHandler, System.Web.EndEventHandler endHandler, System.Web.EndEventHandler timeoutHandler, object state);

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

PageAsyncTask(BeginEventHandler, EndEventHandler, EndEventHandler, Object, Boolean)

Initializes a new instance of the PageAsyncTask class using the specified value for executing in parallel.

C#
public PageAsyncTask(System.Web.BeginEventHandler beginHandler, System.Web.EndEventHandler endHandler, System.Web.EndEventHandler timeoutHandler, object state, bool executeInParallel);

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.

C#
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);

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.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1