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.