[ 来源:http://www.it55.com | 作者: | 时间:2007-09-07 | 收藏 | 推荐 ] 【大 中 小】
基本思路:将需要后台处理的任务定义成一个ExecItem对象.用户提交操作后,系统将就操作转成一个ExecItem对象加入到BkExecManager(后台处理管理对象)中的一个先入先出的队列中. http://www.it55.com
网站在启动时会自动启动BkExecManager,而BkExecManager则启动一个定时器来定时处理后台任务队列. 精美韩国模版下载http://www.it55.com
在处理完成时BkExecManager就队列中移去任务对象,如果操作失败将以邮件方式通知管理员来完成问题处理. 免费矢量图片素材下载http://www.it55.com
呵.现在贴代码! IT资讯之家 http://www.it55.com
1,后台处理管理对象
public class BkExecManager
{ //定时回调。
private static TimerCallback timerDelegate;
private static Timer stateTimer;
private static BkExecer m_Execer;
public static string DataPath;
public static string BkManager = "XXXX";
public static int BkBufSize = 100; 免费网页模版下载http://www.it55.com
private static int Interval = 10000; http://www.it55.com在线教程
public static BkExecer Execer
{
get { return m_Execer; }
} http://www.it55.com
static BkExecManager()
{
DataPath = System.AppDomain.CurrentDomain.BaseDirectory + "BkItem\\";
if (System.Configuration.ConfigurationManager.AppSettings["Interval"] != null)
Interval = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Interval"]);
if (System.Configuration.ConfigurationManager.AppSettings["BkBufSize"] != null)
BkBufSize = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["BkBufSize"]);
if (System.Configuration.ConfigurationManager.AppSettings["BkManager"] != null)
BkManager = System.Configuration.ConfigurationManager.AppSettings["BkManager"];
http://www.it55.com/
m_Execer = new BkExecer();
//初始化回调
timerDelegate = new TimerCallback(m_Execer.DoBkExec); http://www.it55.com
//初始化定时器
stateTimer = new Timer(timerDelegate, null, 5000, Interval);
}
/// <summary>
/// 停止定时器.
/// </summary>
static void BkExecQuit()
{
stateTimer.Dispose();
}
} sflj http://www.it55.com kg^&fgd
2,后台处理执行
public class BkExecer
{
//维护一
个前进前出的队列。
private Queue<ExecItem> m_BkExecItemList;
private static object lockHelper = new object();
private static bool m_IsBusy = false;
public static bool IsBusy
{
get
{
return m_IsBusy;
}
}
45398 http://www.it55.com it55学习IT知识,享受IT生活 4dfkjn
public BkExecer()
{
m_BkExecItemList = new Queue<ExecItem>(BkExecManager.BkBufSize); 45398 http://www.it55.com it55学习IT知识,享受IT生活 4dfkjn
(编辑:IT资讯之家 www.it55.com)