PageAsyncTask.TimeoutHandler Property


Gets the method to call when the task does not complete successfully within the time-out period.

Namespace:   System.Web.UI
Assembly:  System.Web (in System.Web.dll)

public EndEventHandler TimeoutHandler { get; private set; }

Property Value

Type: System.Web.EndEventHandler

An EndEventHandler delegate that represents the method to call when the task does not complete successfully within the time-out period.

The TimeoutHandler delegate is set in the constructor.

The following code example registers three asynchronous tasks to a page and executes them in parallel. Each task calls a method that merely causes the thread to sleep for 5 seconds. A TimeoutHandler delegate is specified for each task.

<%@ Page Language="C#" Async="true" AsyncTimeout="35"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  protected void Page_Load(object sender, EventArgs e)

    // Define the asynchronuous task.
    Samples.AspNet.CS.Controls.SlowTask slowTask1 =    
      new Samples.AspNet.CS.Controls.SlowTask();
    Samples.AspNet.CS.Controls.SlowTask slowTask2 =
    new Samples.AspNet.CS.Controls.SlowTask();
    Samples.AspNet.CS.Controls.SlowTask slowTask3 =
    new Samples.AspNet.CS.Controls.SlowTask();

    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.

    // Execute the register asynchronous task.

    TaskMessage.InnerHtml = slowTask1.GetAsyncTaskProgress()+ "<br />" + slowTask2.GetAsyncTaskProgress() + "<br />" + slowTask3.GetAsyncTaskProgress();


<html xmlns="" >
<head id="Head1" runat="server">
    <title>Asynchronous Task Example</title>
    <form id="form1" runat="server">
      <span id="TaskMessage" runat="server">
using System;
using System.Web;
using System.Web.UI;
using System.Threading;

namespace Samples.AspNet.CS.Controls
    public class SlowTask
        private String _taskprogress;
        private AsyncTaskDelegate _dlgt;

        // Create delegate.
        protected delegate void AsyncTaskDelegate();

        public String GetAsyncTaskProgress()
            return _taskprogress;
        public void ExecuteAsyncTask()
            // Introduce an artificial delay to simulate a delayed 
            // asynchronous task.

        // Define the method that will get called to
        // start the asynchronous task.
        public IAsyncResult OnBegin(object sender, EventArgs e,
            AsyncCallback cb, object extraData)
            _taskprogress = "AsyncTask started at: " + DateTime.Now + ". ";

            _dlgt = new AsyncTaskDelegate(ExecuteAsyncTask);
            IAsyncResult result = _dlgt.BeginInvoke(cb, extraData);

            return result;

        // Define the method that will get called when
        // the asynchronous task is ended.
        public void OnEnd(IAsyncResult ar)
            _taskprogress += "AsyncTask completed at: " + DateTime.Now;

        // Define the method that will get called if the task
        // is not completed within the asynchronous timeout interval.
        public void OnTimeout(IAsyncResult ar)
            _taskprogress += "AsyncTask failed to complete " +
                "because it exceeded the AsyncTimeout parameter.";

.NET Framework
Available since 2.0
Return to top