当前位置:编程学习 > asp >>

asp.net如何在事件中启动线程来打开一个页面

在页面点击一个按钮,其目的是在按钮中做两件事情,一件需要点击按钮马上完成,另一件事情是点击按钮后做其他事情。如果按顺序一次做完感觉特别耗时,下面简单罗列一下。[csharp] view plaincopyprint?
protected void Button1_Click(object sender, EventArgs e) 
    { 
        Label1.Text = TextBox1.Text; 
 
      //在这做第一件事情 

protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = TextBox1.Text;

   //在这做第一件事情[csharp] view plaincopyprint?
dowork(); 

   dowork();[csharp] view plaincopyprint?
//做完后马上启动线程  
     System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadChild)); 
     thread.Start(); 
 } 

   //做完后马上启动线程
        System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadChild));
        thread.Start();
    }

线程中处理完后打开一个窗口

public void ThreadChild()

{

        Label2.Text = DateTime.Now.ToString();

         //Response.Write("");

         //响应http必然报错

         //Response.Write("<script>window.open('login.aspx','','');</script>");

         //通过注册即可打开窗口

          Page.RegisterStartupScript("", "<script>window.open('login.aspx','','');</script>");

 }

 

补充:Web开发 , ASP.Net ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,