国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
asp.net 定時(shí)器
在使用WinForm編程中,我們可以使用定時(shí)器實(shí)現(xiàn)規(guī)定周期的定時(shí)工作進(jìn)行操作,而在Asp.Net 如何操作,卻是個(gè)問題。

而在Asp.Net Forums中有很好的例子,定時(shí)器應(yīng)用如下:
1. 更新論壇統(tǒng)計(jì)信息
2. 定時(shí)索引指定條數(shù)的帖子
3. 定時(shí)群發(fā)隊(duì)列中的郵件

Forums中對(duì)定時(shí)器的調(diào)用是放在自定義HttpModule的Init方法中(如果您沒有使用HttpModule,也可以在Globals.aspx中的Application_OnStart 中調(diào)用定時(shí)器)。

      // 定時(shí)器 
        static Timer statsTimer; 
        static Timer emailTimer; 
 
        // 定時(shí)間隔 
        private long EmailInterval = ForumConfiguration.GetConfig().ThreadIntervalEmail * 60000; 
        private long StatsInterval = ForumConfiguration.GetConfig().ThreadIntervalStats * 60000; 
 
        public String ModuleName {  
            get { return "ForumsHttpModule"; }  
        }     
 
 
        // ********************************************************************* 
        //  ForumsHttpModule 
        // 
        /**//// <summary> 
        /// Initializes the HttpModule and performs the wireup of all application 
        /// events. 
        /// </summary> 
        /// <param name="application">Application the module is being run for</param> 
        public void Init(HttpApplication application) {  
 
            // Wire-up application events 
            // 
            // 略去其他代碼 
             
            ForumConfiguration forumConfig = ForumConfiguration.GetConfig(); 
 
            // 如果使用定時(shí)器并且定時(shí)器還沒初始化 
            if( forumConfig != null 
            &&  forumConfig.IsBackgroundThreadingDisabled == false ) { 
                if (emailTimer == null) 
                    // 新建定時(shí)器 
                    // 新建一個(gè)TimerCallback委托,具體要執(zhí)行的方法在ScheduledWorkCallbackEmailInterval中 
                    emailTimer = new Timer(new TimerCallback(ScheduledWorkCallbackEmailInterval), application.Context, EmailInterval, EmailInterval); 
 
                if( forumConfig.IsIndexingDisabled == false  
                &&    statsTimer == null ) { 
                    statsTimer = new Timer(new TimerCallback(ScheduledWorkCallbackStatsInterval), application.Context, StatsInterval, StatsInterval); 
            } 
        } 
        } 
 
        /**//// <summary> 
        /// 釋放定時(shí)器 
        /// </summary> 
        public void Dispose() { 
            statsTimer = null; 
            emailTimer = null; 
        } 
 
        Timer Callbacks#region Timer Callbacks 
        /**//// <summary> 
        /// 定時(shí)發(fā)送隊(duì)列中待發(fā)送的郵件 
        /// </summary> 
        private void ScheduledWorkCallbackEmailInterval (object sender) { 
            try { 
                // 當(dāng)處理郵件時(shí)暫停定時(shí)器 
                emailTimer.Change( System.Threading.Timeout.Infinite, EmailInterval ); 
 
                // 發(fā)送隊(duì)列中的郵件 
                // 
                Emails.SendQueuedEmails( (HttpContext) sender); 
 
 
                // 更新匿名用戶 
                // 
                Users.UpdateAnonymousUsers( (HttpContext) sender); 
            } 
            catch( Exception e ) { 
                ForumException fe = new ForumException( ForumExceptionType.EmailUnableToSend, "Scheduled Worker Thread failed.", e ); 
                fe.Log(); 
            } 
            finally { 
                // 重新啟動(dòng)定時(shí)器 
                emailTimer.Change( EmailInterval, EmailInterval ); 
            } 
        } 
 
        /**//// <summary> 
        /// 定時(shí)索引帖子和定時(shí)更新論壇統(tǒng)計(jì)信息 
        /// </summary> 
        private void ScheduledWorkCallbackStatsInterval(object sender) { 
            try { 
                // 休眠定時(shí)器 
                statsTimer.Change( System.Threading.Timeout.Infinite, StatsInterval ); 
 
                // 每次索引100篇帖子 
                // 
                Search.IndexPosts( (HttpContext) sender, 100); 
 
                // 更新論壇統(tǒng)計(jì)信息 
                SiteStatistics.LoadSiteStatistics( (HttpContext) sender, true, 1 ); 
            } 
            catch( Exception e ) { 
                ForumException fe = new ForumException( ForumExceptionType.UnknownError, "Failure performing scheduled statistics maintenance.", e ); 
                fe.Log(); 
            } 
            finally { 
                // 喚醒定時(shí)器 
                statsTimer.Change( StatsInterval, StatsInterval); 
            } 
        } 
        #endregion 
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
普彩定時(shí)器
STC單片機(jī)對(duì)逆變器的設(shè)計(jì)
一個(gè)簡單、輕量、功能非常強(qiáng)大的C#/ASP.NET定時(shí)任務(wù)執(zhí)行管理器組件–FluentScheduler
[求助]VBA如何實(shí)現(xiàn)每天特定時(shí)間執(zhí)行一個(gè)動(dòng)作?
微波爐定時(shí)器學(xué)習(xí)
[第57講]特殊定時(shí)器指令
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服