当前位置:Gxlcms > asp.net > asp.net在事件中启动线程来打开一个页面的实现方法

asp.net在事件中启动线程来打开一个页面的实现方法

时间:2021-07-01 10:21:17 帮助过:11人阅读

在页面点击一个按钮,其目的是在按钮中做两件事情,一件需要点击按钮马上完成,另一件事情是点击按钮后做其他事情。如果按顺序一次做完感觉特别耗时,下面简单罗列一下。

  1. protected void Button1_Click(object sender, EventArgs e)
  2. {
  3. Label1.Text = TextBox1.Text;
  4. //在这做第一件事情
  5. dowork();
  6. //做完后马上启动线程
  7. System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadChild));
  8. thread.Start();
  9. }

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

  1. public void ThreadChild()
  2. {
  3. Label2.Text = DateTime.Now.ToString();
  4. //Response.Write("");
  5. //响应http必然报错
  6. //Response.Write("<script>window.open('login.aspx','','');</script>");
  7. //通过注册即可打开窗口
  8. Page.RegisterStartupScript("", "<script>window.open('login.aspx','','');</script>");
  9. }

人气教程排行