62,052
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm5.aspx.cs" Inherits="web.WebForm5" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager" runat="server" />
<asp:UpdatePanel ID="upList" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Timer ID="tmUpdate" runat="server" Enabled="false" OnTick="tmUpdate_Tick" Interval="2000" />
</ContentTemplate>
</asp:UpdatePanel>
<div>
</div>
</form>
</body>
</html>
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)
{
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.Threading.Thread.Sleep(3000);
System.Web.SessionState.HttpSessionState session = (System.Web.SessionState.HttpSessionState)_Session;
System.Threading.Thread.Sleep(3000);
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);
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Session[Session.SessionID] = "0";
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)
//{
//}
}