Export (0) Print
Expand All
Expand Minimize

Page.AsyncTimeout Property

This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.

Gets or sets a value indicating the time-out interval used when processing asynchronous tasks.

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

'Declaration
<BrowsableAttribute(False)> _
Public Property AsyncTimeout As TimeSpan
<asp:Page AsyncTimeout="TimeSpan" />

Property Value

Type: System.TimeSpan
A TimeSpan that contains the allowed time interval for completion of the asynchronous task. The default time interval is 45 seconds.

ExceptionCondition
ArgumentException

The property was set to a negative value.

The asynchronous time-out of the page represents the amount of time that the page will wait to perform asynchronous tasks. In most circumstances, do not set this property in code. Set the page asynchronous time-out interval using the pages element of the Web configuration file or in the @ Page directive. Values set in the page configuration section are overwritten by the page directive.

Define your asynchronous task using the PageAsyncTask class and register a beginning, an ending, and a time-out handler. If the asynchronous task does not complete in the time interval specified, the time-out handler will be invoked.

The following code example demonstrates the use of the AsyncTimeout property with the ExecuteRegisteredAsyncTasks and RegisterAsyncTask methods. Note the use of beginning, ending, and time-out handlers. In the example, an artificial delay is introduced to demonstrate the situation of an asynchronous task exceeding the allotted time for the task as specified in the AsyncTimeout property. In a real-world scenario, an asynchronous task could be used to perform database calls or image generation, for example, and the time-out handler provides graceful degradation if the task is not performed in a specified amount of time. Note that the AsyncTimeout property is set in the page directive.

<%@ Page Language="VB" AsyncTimeout="2"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    ' Define the asynchronuous task.
    Dim mytask As New Samples.AspNet.VB.Controls.MyAsyncTask()
    Dim asynctask As New PageAsyncTask(AddressOf mytask.OnBegin, AddressOf mytask.OnEnd, AddressOf mytask.OnTimeout, DBNull.Value)

    ' Register the asynchronous task.
    Page.RegisterAsyncTask(asynctask)

    ' Execute the register asynchronous task.
    Page.ExecuteRegisteredAsyncTasks()

    TaskMessage.InnerHtml = mytask.GetAsyncTaskProgress()

  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Asynchronous Task Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <span id="TaskMessage" runat="server">
      </span>
    </div>
    </form>
</body>
</html>
Imports Microsoft.VisualBasic
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Threading

Namespace Samples.AspNet.VB.Controls

    Public Class MyAsyncTask

        Private _taskprogress As String 
        Private _dlgt As AsyncTaskDelegate

        ' Create delegate. 
        Delegate Function AsyncTaskDelegate()

        Public Function GetAsyncTaskProgress() As String 
            Return _taskprogress
        End Function 

        Public Function DoTheAsyncTask()

            ' Introduce an artificial delay to simulate a delayed  
            ' asynchronous task. Make this greater than the  
            ' AsyncTimeout property.
            Thread.Sleep(TimeSpan.FromSeconds(5.0))

        End Function 


        ' Define the method that will get called to 
        ' start the asynchronous task. 
        Public Function OnBegin(ByVal sender As Object, ByVal e As EventArgs, ByVal cb As AsyncCallback, ByVal extraData As Object) As IAsyncResult

            _taskprogress = "Beginning async task." 

            Dim _dlgt As New AsyncTaskDelegate(AddressOf DoTheAsyncTask)
            Dim result As IAsyncResult = _dlgt.BeginInvoke(cb, extraData)
            Return result

        End Function 'OnBegin

        ' Define the method that will get called when 
        ' the asynchronous task is ended. 
        Public Sub OnEnd(ByVal ar As IAsyncResult)

            _taskprogress = "Asynchronous task completed."
            _dlgt.EndInvoke(ar)

        End Sub 

        ' Define the method that will get called if the task 
        ' is not completed within the asynchronous timeout interval. 
        Public Sub OnTimeout(ByVal ar As IAsyncResult)

            _taskprogress = "Ansynchronous task failed to complete because " & _
            "it exceeded the AsyncTimeout parameter." 

        End Sub 

    End Class 

End Namespace

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft