Este artigo foi traduzido por máquina. Para visualizar o arquivo em inglês, marque a caixa de seleção Inglês. Você também pode exibir o texto Em inglês em uma janela pop-up, movendo o ponteiro do mouse sobre o texto.
Tradução
Inglês

Propriedade Page.AsyncTimeout

 

Esta API dá suporte à infraestrutura produto e não se destina a ser usada diretamente do seu código.

Obtém ou define um valor que indica o intervalo de tempo limite usado durante o processamento de tarefas assíncronas.

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

[BrowsableAttribute(false)]
public TimeSpan AsyncTimeout { get; set; }

Valor da Propriedade

Type: System.TimeSpan

Um TimeSpan que contém o intervalo de tempo permitido para a conclusão da tarefa assíncrona. O intervalo de tempo padrão é de 45 segundos.

Exception Condition
ArgumentException

A propriedade foi definida com um valor negativo.

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 of the Web configuration file or in the directive. Values set in the page configuration section are overwritten by the page directive.

Define your asynchronous task using the T:System.Web.UI.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 P:System.Web.UI.Page.AsyncTimeout property with the M:System.Web.UI.Page.ExecuteRegisteredAsyncTasks and M:System.Web.UI.Page.RegisterAsyncTask(System.Web.UI.PageAsyncTask) 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 P:System.Web.UI.Page.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 P:System.Web.UI.Page.AsyncTimeout property is set in the page directive.

<%@ 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>
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.";
		}
	}
}

.NET Framework
Disponível desde 2.0
Retornar ao início
Mostrar: