TAILIEUCHUNG - ASP.NET 4 Unleased - p 95

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 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 Pages When you take advantage of asynchronous methods you must also enable asynchronous page execution. You enable an asynchronous 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 method. For example the page in Listing 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 @ Page Language C Async true AsyncTimeout 5 Trace true @ Import Namespace DOCTYPE html PUBLIC - W3C DTD XHTML Transitional EN http TR xhtml1 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 task Fire off asynchronous tasks lAsyncResult BeginGetData object sender EventArgs e AsyncCallback callback object state Show Page .