Asp.net starts the thread in the event to open a page implementation method, asp.net thread

Source: Internet
Author: User
Tags net thread

Asp.net starts the thread in the event to open a page implementation method, asp.net thread

Click a button on the page to do two things in the button, one is to click the button to finish immediately, and the other is to do other things after clicking the button. If it takes a lot of time to finish the task in sequence, let's take a look at it.

Protected void button#click (object sender, EventArgs e) {Label1.Text = TextBox1.Text; // do the first thing dowork () here; // start the thread System immediately after completion. threading. thread thread = new System. threading. thread (new System. threading. threadStart (ThreadChild); thread. start ();}

Open a window after processing in the thread

Public void ThreadChild () {Label2.Text = DateTime. now. toString (); // Response. write (""); // an error is inevitable when an http Response is returned. // Response. write ("<script> window. open ('login. aspx ', '',''); </script> "); // you can open the window Page after registration. registerStartupScript ("", "<script> window. open ('login. aspx ', '',''); </script> ");}

How does aspnet start a thread in an event to open a page?

Click a button on the page to do two things in the button, one is to click the button to finish immediately, and the other is to do other things after clicking the button. If it takes a lot of time to finish the task in sequence, let's take a look at it. [Csharp] view plaincopyprint? Protected void button#click (object sender, incluvoid button#click (object sender, EventArgs e) {Label1.Text = TextBox1.Text; // protected void button#click (object sender, EventArgs e) {Label1.Text = TextBox1.Text; // do the first thing here [csharp] view plaincopyprint? Dowork (); // immediately start the thread System. threading. thread thread = new System. threading. thread (new System. threading. threadStart (ThreadChild); thread. start ();} // Start the thread System immediately after completion. threading. thread thread = new System. threading. thread (new System. threading. threadStart (ThreadChild); thread. start ();} open a window after processing in the thread public void ThreadChild () {Label2.Text = DateTime. now. toString (); // Response. write (); // an error must be reported in Response to http // Response. write (<scriptwindow. open ('login. aspx ', '',''); </script); // The window can be opened after registration.

The aspnet program only enables threads once.

Open global. asax. cs and call your XX. Start () method in Application_Start. Application_Start is executed only once when the website is requested for the first time.

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.