62,267
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace web
{
public partial class WebForm5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void tmUpdate_Tick(object sender, EventArgs e)
{
if (Session[Session.SessionID] != null)
{
TextBox1.Text = Session[Session.SessionID].ToString();
if (TextBox1.Text == "100")
{
Session.Remove(Session.SessionID);
tmUpdate.Enabled = false;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
//Session[Request.Url.ToString()] = DateTime.Now;
//这里是启动多线程
System.Threading.Thread NewTh = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(Update));
//System.Threading.Thread NewTh = new System.Threading.Thread(new System.Threading.ThreadStart(Update));
NewTh.SetApartmentState(System.Threading.ApartmentState.STA);
NewTh.Start(Session);
tmUpdate.Enabled = true;
//while (NewTh.ThreadState == System.Threading.ThreadState.Running)
//{
//}
}
void Update(Object _Session)
{
//System.Web.HttpContext.Current.Session["1"] = DateTime.Now;
System.Web.SessionState.HttpSessionState session = (System.Web.SessionState.HttpSessionState)_Session;
session[session.SessionID] = "10";
System.Threading.Thread.Sleep(3000);
Session[session.SessionID] = "30";
System.Threading.Thread.Sleep(3000);
Session[session.SessionID] = "50";
System.Threading.Thread.Sleep(3000);
Session[session.SessionID] = "80";
System.Threading.Thread.Sleep(3000);
Session[session.SessionID] = "100";
System.Threading.Thread.Sleep(3000);
}
}
}