当前位置:首页>网络学院>程序开发>ASP.NET教程>文章内容

Asp.net定时执行任务实现类

[ 来源: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\\";

免费网页模版下载http://www.it55.com

            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/


   精美韩国模版下载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);

免费壁纸下载http://www.it55.com

        }

sflj http://www.it55.com kg^&fgd

        /// <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

返回顶部
共5页: 上一页 1 [2] [3] [4] [5] 下一页  
上一篇:医生护士 医生图片平面设计素材医生16   下一篇:没有了

网友评论

[以下评论为网友观点,不代表本站。请自觉遵守互联网相关政策法规,所有连带责任均有评论者自负。]
[不超过250字]