惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V2EX - 技术
V2EX - 技术
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Latest news
Latest news
T
The Exploit Database - CXSecurity.com
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
L
Lohrmann on Cybersecurity
aimingoo的专栏
aimingoo的专栏
B
Blog
T
Threat Research - Cisco Blogs
罗磊的独立博客
Application and Cybersecurity Blog
Application and Cybersecurity Blog
P
Proofpoint News Feed
P
Palo Alto Networks Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
博客园 - 司徒正美
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
T
Tor Project blog
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
Martin Fowler
Martin Fowler
酷 壳 – CoolShell
酷 壳 – CoolShell
Recorded Future
Recorded Future
D
DataBreaches.Net
Y
Y Combinator Blog
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
B
Blog RSS Feed
Scott Helme
Scott Helme
P
Proofpoint News Feed
V
Vulnerabilities – Threatpost
A
Arctic Wolf
Help Net Security
Help Net Security
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Vercel News
Vercel News
AWS News Blog
AWS News Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Schneier on Security
Hacker News: Ask HN
Hacker News: Ask HN
N
Netflix TechBlog - Medium
L
LangChain Blog
博客园 - 叶小钗
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
M
MIT News - Artificial intelligence
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
W
WeLiveSecurity

博客园 - HelloSnoopy

写了个用一个文件定义样式的DataGrid 一个最基本的WebService+Flash调用的实例 [转载]如何奔向程序员打工的出头之日? 一定要讲给孩子们的20个小故事 人脉对职业生涯最重要 (转) 爱情的10种样子,送给懂爱的朋友们 装了Enterprise Library.NET 200501release C#判断是否为数字的最好速度! 开源的 BugTracker.net 错误跟踪管理系统 Enjoy new year of 2005! Flash AS2 用EventDispatcher广播事件 设计模式随笔-让众口不再难调 CodeSmith使用心得 [专题]MVC构架模式 使用Microsoft Application Block之Cache Application 用一条SQL完成数据表的行统计 如何使IFrame的长宽与内容自动适应大小 为Project提供一个统一风格的DataGrid 用于读取树形任一节点下所有级别子节点的SqlServer UDF
asp.net forums中定时器的应用
HelloSnoopy · 2004-12-21 · via 博客园 - HelloSnoopy

src:http://blog.joycode.com/dotey/archive/2004/12/20/41438.aspx

在Asp.Net中使用定时器,破宝之前已有Blog写过《在 ASP.NET 中使用计时器(Timer)》,这里主要针对Asp.Net Forums来说一下其具体实现。

在Asp.Net Forums中,对定时器有如下应用:
1. 更新论坛统计信息
2. 定时索引指定条数的帖子
3. 定时群发队列中的邮件

Forums中对定时器的调用是放在自定义HttpModule的Init方法中(如果您没有使用HttpModule,也可以在Globals.aspx中的Application_OnStart 中调用定时器)。

        // 定时器
        static Timer statsTimer;
        
static Timer emailTimer;

        
// 定时间隔
        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();

            
// 如果使用定时器并且定时器还没初始化
            if( forumConfig != null
            
&&  forumConfig.IsBackgroundThreadingDisabled == false ) {
                
if (emailTimer == null)
                    
// 新建定时器
                    
// 新建一个TimerCallback委托,具体要执行的方法在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>
        
/// 释放定时器
        
/// </summary>

        public void Dispose() {
            statsTimer 
= null;
            emailTimer 
= null;
        }


        
Timer Callbacks

其实稍加改进就可以应用到我们自己的项目中,例如前不久刚做一个项目,因为数据量过于庞大,每次从数据库取非常慢,然后改成使用定时器,每隔12小时将最新的数据列表生成静态的文本。

BTW: 有技术八股文之嫌哦:P