本文整理匯總了C#中System.Web.UI.PageAsyncTask類的典型用法代碼示例。如果您正苦於以下問題:C# PageAsyncTask類的具體用法?C# PageAsyncTask怎麽用?C# PageAsyncTask使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PageAsyncTask類屬於System.Web.UI命名空間,在下文中一共展示了PageAsyncTask類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: AsyncTaskDelegate
//引入命名空間
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.
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 = "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;
_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 += "AsyncTask failed to complete " +
"because it exceeded the AsyncTimeout parameter.";
}
}
}