无为清净楼资源网 Design By www.qnjia.com
前台用ajax不停进行查询,直到任务完成。进度条用的是jquery-ui。后台用一般处理程序处理相应,进度信息保存在HttpContext.Application中。
代码作为简单示例,实际应用时应对资源释放、防止多线程混乱等做进一步控制。
效果图:
代码:
前台:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script src="/UploadFiles/2021-04-02/jquery-2.1.4.min.js">后台:
// 2015年12月16日 09:53:11 // David Huang // 进度条示例 namespace ProgressTest { using System; using System.Threading; using System.Web; /// <summary> /// Handler1 的摘要说明 /// </summary> public class Handler1 : IHttpHandler { // context private HttpContext context; public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { this.context = context; if (context.Request["RequestType"] == "AjaxRequest") { if (context.Request["Method"] == "GetProgress") { context.Response.Clear(); context.Response.Write(this.GetProgress()); context.Response.End(); } else { this.DoWork(); } } } /// <summary> /// 开始工作 /// </summary> private void DoWork() { for (int i = 0; i < 100; i++) { // 记录进度 // 实际应用中需要进一步控制(利用用户信息、cookies等),防止并发造成混乱 this.context.Application["progress"] = i + 1; Random r = new Random(); Thread.Sleep(r.Next(10, 100)); } // 完成后释放资源 this.context.Application["progress"] = null; } /// <summary> /// 查询进度 /// </summary> /// <returns>进度</returns> private int GetProgress() { if (this.context.Application["progress"] != null) { return (int)this.context.Application["progress"]; } else { return -1; } } } }以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年10月04日
2024年10月04日
- 纪钧瀚《胎教古典音乐 钢琴与大提琴的沉浸时光》[320K/MP3][148.91MB]
- 刘雅丽.2001-丽花皇后·EMI精选王【EMI百代】【FLAC分轨】
- 齐秦.1994-黄金十年1981-1990CHINA.TOUR.LIVE精丫上华】【WAV+CUE】
- 群星.2008-本色·百代音乐人创作专辑【EMI百代】【WAV+CUE】
- 群星.2001-同步过冬AVCD【环球】【WAV+CUE】
- 群星.2020-同步过冬2020冀待晴空【环球】【WAV+CUE】
- 沈雁.1986-四季(2012梦田复刻版)【白云唱片】【WAV+CUE】
- 纪钧瀚《胎教古典音乐 钢琴与大提琴的沉浸时光》[FLAC/分轨][257.88MB]
- 《国语老歌 怀旧篇 3CD》[WAV/分轨][1.6GB]
- 班得瑞原装进口《第九张新世纪专辑:微风山谷》1CD[APE/CUE分轨][331MB]
- 陈慧琳.2008-Love.Fighters演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 米志宏.1994-HAPPY1994【波丽佳音】【WAV+CUE】
- 潘美辰.2006-最冷的夏天(引进版)【美梦辰真】【WAV+CUE】
- 班得瑞原装进口《第十张新世纪专辑:月光水岸》1CD[APE/CUE分轨][277.2MB]
- 班得瑞原装进口《第十一张新世纪专辑:雾色山脉》1CD[APE/CUE分轨][291.6MB]