62,046
社区成员
发帖
与我相关
我的任务
分享
<%@ WebHandler Language="C#" Class="GetSessionHandler" %>
using System;
using System.Web;
public class GetSessionHandler : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
String tempStr = context.Session["a"] != null ? context.Session["a"].ToString() : "";
context.Response.Write(tempStr);
}
public bool IsReusable {
get {
return false;
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" EnableSessionState="True" CodeFile="MultiThread.aspx.cs" Inherits="ajax_jquery_MultiThread" %>
<!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>
<script src="jquery-1.2.6.min.js"></script>
<script>
function ajaxGet()
{
$.get("GetSessionHandler.ashx",{date:new Date()},
function(data){
var num=parseInt(data);
if((!isNaN(num))&&(num<100))
{
$("#result").text(num+"%");
window.setTimeout(ajaxGet, 1000);
}
else if((!isNaN(num))&&(num==100))
{
$("#result").text("100%");
window.setTimeout('$("#result").text("发送已完成");', 2000);
}
}
);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="btn" runat="server" Text="上传" OnClick="btn_Click" />
<div id="result"></div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class ajax_jquery_MultiThread : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Click(object sender, EventArgs e)
{
Session["a"] = "0";
System.Threading.Thread NewTh = new System.Threading.Thread(new System.Threading.ThreadStart(Update));
NewTh.Start();
ClientScript.RegisterStartupScript(this.GetType(), "ajaxGet", "ajaxGet();", true);
}
void Update()
{
try
{
//模拟邮件发送
Session["a"] = "10";
System.Threading.Thread.Sleep(3000);
Session["a"] = "30";
System.Threading.Thread.Sleep(3000);
Session["a"] = "50";
System.Threading.Thread.Sleep(3000);
Session["a"] = "80";
System.Threading.Thread.Sleep(3000);
Session["a"] = "100";
System.Threading.Thread.Sleep(3000);
}
catch (Exception ee)
{
String exceptionStr = ee.StackTrace;
}
}
}