Page.AsyncTimeout 속성

정의

비동기 작업을 처리할 때 사용되는 시간 제한 간격을 나타내는 값을 가져오거나 설정합니다.

public:
 property TimeSpan AsyncTimeout { TimeSpan get(); void set(TimeSpan value); };
[System.ComponentModel.Browsable(false)]
public TimeSpan AsyncTimeout { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.AsyncTimeout : TimeSpan with get, set
Public Property AsyncTimeout As TimeSpan

속성 값

TimeSpan

비동기 작업을 완료하는 데 허용되는 시간 간격이 포함된 TimeSpan입니다. 기본 시간 간격은 45초입니다.

특성

예외

속성이 음수값으로 설정되었습니다.

예제

다음 코드 예제에서는 및 메서드와 AsyncTimeout 함께 속성을 사용하는 방법을 ExecuteRegisteredAsyncTasks RegisterAsyncTask 보여 줍니다. 시작, 종료 및 제한 시간 처리기를 사용합니다. 이 예제에서는 속성에 지정된 대로 작업에 할당된 시간을 초과하는 비동기 작업의 상황을 보여 주는 인공 지연이 AsyncTimeout 도입됩니다. 예를 들어 실제 시나리오에서는 비동기 작업을 사용하여 데이터베이스 호출 또는 이미지 생성을 수행할 수 있으며, 지정된 시간 동안 작업이 수행되지 않으면 시간 제한 처리기가 정상적인 성능 저하를 제공합니다. 속성은 AsyncTimeout 페이지 지시문에 설정됩니다.

<%@ Page Language="C#" 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 void Page_Load(object sender, EventArgs e)
  {
    // Define the asynchronuous task.
    Samples.AspNet.CS.Controls.MyAsyncTask mytask =    
      new Samples.AspNet.CS.Controls.MyAsyncTask();
    PageAsyncTask asynctask = new PageAsyncTask(mytask.OnBegin, mytask.OnEnd, mytask.OnTimeout, null);

    // Register the asynchronous task.
    Page.RegisterAsyncTask(asynctask);
      
    // Execute the register asynchronous task.
    Page.ExecuteRegisteredAsyncTasks();

    TaskMessage.InnerHtml = mytask.GetAsyncTaskProgress();

  }
</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>
<%@ 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>
using System;
using System.Web;
using System.Web.UI;
using System.Threading;

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

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

        public String GetAsyncTaskProgress()
        {
            return _taskprogress;
        }
        public void DoTheAsyncTask()
        {
            // Introduce an artificial delay to simulate a delayed 
            // asynchronous task. Make this greater than the 
            // AsyncTimeout property.
            Thread.Sleep(TimeSpan.FromSeconds(5.0));
        }

        // Define the method that will get called to
        // start the asynchronous task.
        public IAsyncResult OnBegin(object sender, EventArgs e,
            AsyncCallback cb, object extraData)
        {
            _taskprogress = "Beginning async task.";

            _dlgt = new AsyncTaskDelegate(DoTheAsyncTask);
            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 = "Asynchronous task completed.";
            _dlgt.EndInvoke(ar);
        }

        // Define the method that will get called if the task
        // is not completed within the asynchronous timeout interval.
        public void OnTimeout(IAsyncResult ar)
        {
            _taskprogress = "Ansynchronous task failed to complete " +
                "because it exceeded the AsyncTimeout parameter.";
        }
    }
}
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

설명

페이지의 비동기 시간 제한은 페이지가 비동기 작업을 수행하기 위해 대기하는 시간을 나타냅니다. 대부분의 경우 코드에서 이 속성을 설정하지 마세요. 웹 구성 파일의 페이지 요소 또는 @ Page 지시문을 사용하여 페이지 비동기 시간 제한 간격을 설정합니다. 페이지 구성 섹션에 설정된 값은 페이지 지시문에 의해 덮어씁니다.

클래스를 사용하여 PageAsyncTask 비동기 작업을 정의하고 시작, 종료 및 시간 제한 처리기를 등록합니다. 지정된 시간 간격에서 비동기 작업이 완료되지 않으면 시간 제한 처리기가 호출됩니다.

적용 대상

추가 정보