找传奇、传世资源到传世资源站!

asp.net 异步进程监控

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

可用于大文件上传 以及 需长时间执行的任务,可反馈出任务执行进度,如下图
from clipboard#region Copyright © 2010-2011 Craig P Johnson [craigpj@gmail.com]/* * This software is provided 'as-is', without any express or implied warranty. * In no event will the author(s) be held liable for any damages arising from * the use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. * * 2. Altered source versions must be plainly marked as such, and must not * be misrepresented as being the original software. * * 3. This notice may not be removed or altered from any source distribution. */#endregionusing System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace AsyncProcessor{ public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { ButtonStartAsynchProcess.Visible = true; PanelProcessMonitor.Visible = false; } // add event handlers to execute after the process is complete asyncProcessingMonitor1.ProcessingComplete = new EventHandler(ProcessingComplete); asyncProcessingMonitor1.ProcessingError = new EventHandler(ProcessingError); } protected void ButtonStartAsynchProcess_Click(object sender, EventArgs e) { StartAsynchProcess(); PanelProcessMonitor.Visible = true; } private void StartAsynchProcess() { // generate a sudo random number for this process // I suggest adding the process to a database and using teh unique id // generated. that way you have a record of the process running int seed = int.Parse(DateTime.Now.Ticks.ToString().Substring(0, 9)); int unique_proc_id = new Random(seed).Next(); // create a new AsyncProcessorDetail AsyncProcessorDetail detail = new AsyncProcessorDetail(unique_proc_id, "c:\\path\\to\\your\\file", "filename", 0, "ProcessorExample", 1); // call the AsyncProcessManager and pass it the AsyncProcessorDetail to be processed AsyncProcessManager.StartAsyncProcess(detail); // start the asyncProcessingMonitor control asyncProcessingMonitor1.Start(unique_proc_id, true, "Default.aspx"); } protected void ProcessingComplete(object sender, EventArgs e) { // execute any code here on processing complete } protected void ProcessingError(object sender, EventArgs e) { // display an error warning to your users } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复