Introduction to Asp.net page cycles and acceleration strategies

Source: Internet
Author: User

(Note: This article uses a small part of the ultra-fast Asp.net multi-thread acceleration policy, which is not my original)

 

The entire page cycle of Asp.net is as follows. In the render stage, each control calls its own render method to present itself on the page. In addition, all other stages contain a handle, it can be used for external event response.

 

 

 

Under normal conditions, ASP. NET occupies a separate thread throughout the page cycle. Therefore, we can achieve acceleration through multiple threads: divide the page cycle into two threads for execution.

For example:

 

When should we use a multi-threaded page cycle?

If some operations on some pages take too long, you can consider using multiple threads, such as database read/write, Io operations, and WebService.

 

 

The following is an example:

During page_load, register a new thread:

        protected void Page_Load(object sender, EventArgs e)        {            PageAsyncTask pat =            new PageAsyncTask(BeginAsync, EndAsync, null, null, true);            this.RegisterAsyncTask(pat);         }

The method to start and end the call is as follows:

     private IAsyncResult BeginAsync(object sender, EventArgs e,       AsyncCallback cb, object state)        {            SqlConnection conn = new SqlConnection(ConnString);            conn.Open();            SqlCommand cmd = new SqlCommand("WAITFOR DELAY '00:00:01'", conn);            IAsyncResult ar = cmd.BeginExecuteNonQuery(cb, cmd);            return ar;        }        private void EndAsync(IAsyncResult ar)        {            using (SqlCommand cmd = (SqlCommand)ar.AsyncState)            {                using (cmd.Connection)                {                    int rows = cmd.EndExecuteNonQuery(ar);                }            }        } 

Principle: one thread is split to allow a thread to wait for the idle time of a time-consuming page operation to do other things. However, if the web application thread is very busy and the CPU is running, resulting in no intermittent time, the use of synchronization tasks will lead to additional performance bottlenecks, which must be avoided.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.