Ajax|asp.net| Solutions | web | issues
Summary: asp.net provides several solutions for quite time-consuming processing. One of the best ways to do this is to combine threads with query scenarios or AJAX techniques.
First, the preface
People have to wait. In fact, when users are working on a computer, they generally get bored if they wait more than about 200 milliseconds. This can be a problem when your web-based application uses a process that takes many seconds or even minutes. Obviously, you can't just create a progress bar dialog box or wait for the cursor.
Luckily, ASP. NET provides a number of different solutions to handle this rather time-consuming process-depending on the level of interaction required and how complex you are willing to handle. This article begins by using a sample application to illustrate this problem and runs through two scenarios: one that uses simple query techniques and the other that uses a more advanced AJAX solution.
Be aware that there are some wrong ways to be found in the. NET Framework. One of them is iasynchttphandler-at first glance, it seems to help a longer page request. However, this asynchronous HTTP processor is designed to release the processor-although some tasks on top of a page take some time but do not require any CPU. A good example is to issue a Web request in the middle of a page. In this case, the asynchronous HTTP processor is very efficient.
Ii. Issues
In this article, I want to discuss a different issue. In this sample application, I created a page that reports the current temperature, wind scale, and other weather information for five different airports. The Web service takes about five seconds to get each data. So if I let the page run as shown in Figure 1, it takes about a minute before the server returns to a page-which is an unacceptable wait time for any user.
Figure 1. Wait: The first sample application takes about a minute to load the page. |
The corresponding HTML for this rather time-consuming page is shown in Listing 1 (see download source code for details).
The page Load event code creates a dataset for the data grid. Then, quickly process multiple airports and invoke the Web service to get the data. The method then populates the data from the Web service to the dataset and attaches it to a grid control (see Figure 2).
Figure 2. Basic: The sample application's Web service performs a simple weather condition query. |
The WSDL for this Web service is http://www.capeclear.com/AirportWeather.wsdl. It defines a number of different methods, and I will use only one of the getsummary methods-it returns an airport location, sky conditions, wind speed, visibility, and even more data blocks.
In this way, even a single server request consumes more time than a single page fetch. Another option is to have a thread run in the background to get the data, while the front-end page continuously monitors the output of the thread.
Third, Threading Solutions
Threading solutions provide users with a cleaner experience-because they can be updated periodically. The response here is easy to prepare, although processing in the background may take some time, but in response it can be returned immediately.
To handle this threading system, I will use two classes and one interface. Jobhandler Singleton is responsible for maintaining an object collection-it implements the Ijob interface. This jobhandler manages system threads. A new thread is created for each add job, and the Start method on the work is invoked within a new thread. An ID string that is used for subsequent query work is returned.
The corresponding UML for the job system is shown in Figure 3.
Figure 3. This screenshot shows the corresponding UML for the job system. |
Weatherjob is a ijob implementation-it is responsible for weather queries from a specified set in the airport and populates a dataset called data containing a weather report.
The Jobhandler singleton corresponding code is shown in Listing 2 (see download source code)-fairly straightforward. The only interesting point is the AddJob method, which creates a new thread for the job and invokes the Start method.
The interfaces for these work are shown in Listing 3 (see download source code). The constructor creates a data collection for the work. And the Start method, through each airport, invokes the Web request and stores the returned data in the data collection.
[1] [2] Next page