Anatomy of an ASP.NET Page in C#.NET

Creator Quick Response Code in C#.NET Anatomy of an ASP.NET Page

5 Anatomy of an ASP.NET Page
QR Code JIS X 0510 Creator In C#
Using Barcode creation for .NET Control to generate, create QR Code image in .NET framework applications.
www.OnBarcode.com
Scanning Quick Response Code In Visual C#.NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
String ProcessFeed(String feed) { // Build the page output from the XML input ... } }
Bar Code Creator In C#.NET
Using Barcode creation for Visual Studio .NET Control to generate, create barcode image in Visual Studio .NET applications.
www.OnBarcode.com
Bar Code Scanner In Visual C#
Using Barcode reader for .NET framework Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
As you can see, such an asynchronous page differs from a standard one only for the aforementioned elements the Async directive attribute and the pair of asynchronous event handlers. Figure 5-4 shows the sample page in action.
Generating Quick Response Code In Visual Studio .NET
Using Barcode drawer for ASP.NET Control to generate, create QR Code JIS X 0510 image in ASP.NET applications.
www.OnBarcode.com
Quick Response Code Creation In .NET
Using Barcode generator for .NET framework Control to generate, create QR image in .NET applications.
www.OnBarcode.com
FIGURE 5-4 A sample asynchronous page downloading links from a blog.
QR Code Encoder In Visual Basic .NET
Using Barcode creator for .NET framework Control to generate, create QR Code image in .NET applications.
www.OnBarcode.com
Creating EAN13 In C#
Using Barcode drawer for VS .NET Control to generate, create GS1 - 13 image in .NET framework applications.
www.OnBarcode.com
It would also be interesting to take a look at the messages traced by the page. Figure 5-5 provides visual clues of it. The Begin and End stages are served by different threads and take place at different times. Note the time elapsed between the Exit BeginTask and Enter EndTask stages. It is much longer than intervals between any other two consecutive operations. It s in that interval that the lengthy operation in this case, downloading and processing the RSS feed took place. The interval also includes the time spent to pick up another thread from the pool to serve the second part of the original request.
Code 39 Generation In Visual C#
Using Barcode generator for Visual Studio .NET Control to generate, create Code 39 Extended image in .NET framework applications.
www.OnBarcode.com
Linear Barcode Printer In C#
Using Barcode encoder for .NET framework Control to generate, create Linear Barcode image in VS .NET applications.
www.OnBarcode.com
Part II
DataMatrix Printer In Visual C#
Using Barcode generator for VS .NET Control to generate, create ECC200 image in VS .NET applications.
www.OnBarcode.com
ANSI/AIM ITF 25 Generator In Visual C#.NET
Using Barcode drawer for VS .NET Control to generate, create ITF image in Visual Studio .NET applications.
www.OnBarcode.com
ASP.NET Pages and Server Controls
Decode ECC200 In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Create Code 128A In None
Using Barcode creation for Software Control to generate, create Code 128B image in Software applications.
www.OnBarcode.com
FIGURE 5-5 The traced request details clearly show the two steps needed to process a request
EAN 13 Decoder In C#.NET
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
Data Matrix Scanner In Visual C#.NET
Using Barcode recognizer for .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
asynchronously.
Creating Bar Code In VB.NET
Using Barcode creator for .NET Control to generate, create barcode image in VS .NET applications.
www.OnBarcode.com
Code 128A Reader In Visual Studio .NET
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
The RegisterAsyncTask Method
Bar Code Generation In Visual Basic .NET
Using Barcode printer for .NET framework Control to generate, create barcode image in Visual Studio .NET applications.
www.OnBarcode.com
UPC-A Supplement 2 Generator In None
Using Barcode creation for Online Control to generate, create GTIN - 12 image in Online applications.
www.OnBarcode.com
The AddOnPreRenderCompleteAsync method is not the only tool you have to register an asynchronous task. The RegisterAsyncTask method is, in most cases, an even better solution. RegisterAsyncTask is a void method and accepts a PageAsyncTask object. As the name suggests, the PageAsyncTask class represents a task to execute asynchronously. The following code shows how to rework the sample page that reads some RSS feed and make it use the RegisterAsyncTask method:
void Page_Load (object sender, EventArgs e) { PageAsyncTask task = new PageAsyncTask( new BeginEventHandler(BeginTask), new EndEventHandler(EndTask), null, null); RegisterAsyncTask(task); }
5 Anatomy of an ASP.NET Page
The constructor accepts up to five parameters, as shown in the following code:
public PageAsyncTask( BeginEventHandler beginHandler, EndEventHandler endHandler, EndEventHandler timeoutHandler, object state, bool executeInParallel)
The beginHandler and endHandler parameters have the same prototype as the corresponding handlers you use for the AddOnPreRenderCompleteAsync method. Compared to the AddOnPreRenderCompleteAsync method, PageAsyncTask lets you specify a timeout function and an optional flag to enable multiple registered tasks to execute in parallel. The timeout delegate indicates the method that will get called if the task is not completed within the asynchronous timeout interval. By default, an asynchronous task times out if it s not completed within 45 seconds. You can indicate a different timeout in either the configuration file or the @Page directive. Here s what you need if you opt for the web.config file:
<system.web> <pages asyncTimeout="30" /> </system.web>
The @Page directive contains an integer AsyncTimeout attribute that you set to the desired number of seconds. Just as with the AddOnPreRenderCompleteAsync method, you can pass some state to the delegates performing the task. The state parameter can be any object. The execution of all tasks registered is automatically started by the Page class code just before the async point is reached. However, by placing a call to the ExecuteRegisteredAsyncTasks method on the Page class, you can take control of this aspect.
Choosing the Right Approach
When should you use AddOnPreRenderCompleteAsync, and when is RegisterAsyncTask a better option Functionally speaking, the two approaches are nearly identical. In both cases, the execution of the request is split in two parts: before and after the async point. So where s the difference The first difference is logical. RegisterAsyncTask is an API designed to run tasks asynchronously from within a page and not just asynchronous pages with Async=true. AddOnPreRenderCompleteAsync is an API specifically designed for asynchronous pages. That said, a couple of further differences exist. One is that RegisterAsyncTask executes the End handler on a thread with a richer context than AddOnPreRenderCompleteAsync. The thread context includes impersonation and
Part II
ASP.NET Pages and Server Controls
HTTP context information that is missing in the thread serving the End handler of a classic asynchronous page. In addition, RegisterAsyncTask allows you to set a timeout to ensure that any task doesn t run for more than a given number of seconds. The other difference is that RegisterAsyncTask makes the implementation of multiple calls to remote sources significantly easier. You can have parallel execution by simply setting a Boolean flag, and you don t need to create and manage your own IAsyncResult object. The bottom line is that you can use either approach for a single task, but you should opt for RegisterAsyncTask when you have multiple tasks to execute simultaneously.
Copyright © OnBarcode.com . All rights reserved.