Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Các thuộc tính đầu tiên cho phép thực hiện không đồng bộ trang. Thuộc tính thứ hai chỉ định một giá trị thời gian chờ trong vài giây. Giá trị thời gian chờ xác định lượng thời gian mà trang web cung cấp cho một tập hợp các nhiệm vụ không đồng bộ để hoàn thành trước khi trang vẫn tiếp tục thực hiện. | 914 CHAPTER 19 Building Data Access Components with ADO.NET private string _title private string _director public string Title get return _title set _title value public string Director get return _director set _director value Using Asynchronous ASP.NET Pages When you take advantage of asynchronous ADO.NET methods you must also enable asynchronous ASP.NET page execution. You enable an asynchronous ASP.NET page by adding the following two attributes to a page directive @ Page Async true AsyncTimeout 8 The first attribute enables asynchronous page execution. The second attribute specifies a timeout value in seconds. The timeout value specifies the amount of time that the page gives a set of asynchronous tasks to complete before the page continues execution. After you enable asynchronous page execution you must set up the asynchronous tasks and register the tasks with the page. You represent each asynchronous task with an instance of the PageAsyncTask object. You register an asynchronous task for a page by calling the Page.RegisterAsyncTask method. For example the page in Listing 19.35 displays the records from the Movies database table in a GridView control. The database records are retrieved asynchronously from the AsyncDataLayer component created in the previous section. LISTING 19.35 ShowPageAsyncTask.aspx @ Page Language C Async true AsyncTimeout 5 Trace true @ Import Namespace System.Threading DOCTYPE html PUBLIC - W3C DTD XHTML 1.0 Transitional EN http www.w3.org TR xhtml1 DTD xhtml1-transitional.dtd script runat server From the Library of Wow eBook Executing Asynchronous Database Commands 915 private AsyncDataLayer dataLayer new AsyncDataLayer void Page_Load Setup asynchronous data execution PageAsyncTask task new PageAsyncTask BeginGetData EndGetData TimeoutData null true Page.RegisterAsyncTask task Fire off asynchronous tasks Page.ExecuteRegisteredAsyncTasks lAsyncResult BeginGetData object sender EventArgs e AsyncCallback callback object state Show Page .