logo 广告
Loading...
 导航 所在位置:论坛首页 -> ┈┋电脑网络┋┈ -> Asp/Asp.Net教程 -> 如何保证web app中的Send Email线程稳定性
回复
标题:如何保证web app中的Send Email线程稳定性收藏 编辑 删除 楼主 | 上一篇 下一篇
慕容暖暖
头像
等级:职业侠客
权限:普通用户
积分:71
金钱:245
声望:124
经验:124
发帖数:124
注册:2008年8月30日
资料 短消息2008-9-21 16:44:04

在asp.netforums2或者cs系统中,每过几分种会发送一次email,但是如果在执行时,数据库服务器重启。

会导致SendEmail线程死掉。

参考代码:
privatevoidScheduledWorkCallbackEmailInterval(objectsender)
{
try{
//suspendthetimerwhileweprocessemails
emailTimer.Change(System.Threading.Timeout.Infinite,EmailInterval);

//Sendemails
//
Emails.SendQueuedEmails((HttpContext)sender);


//Updateanonymoususers
//
Users.UpdateAnonymousUsers((HttpContext)sender);

}
catch(Exceptione){
ForumExceptionfe=newForumException(ForumExceptionType.EmailUnableToSend,"ScheduledWorkerThreadfailed.",e);
fe.Log();
}
finally{
emailTimer.Change(EmailInterval,EmailInterval);
}
}

事实上,代码:emailTimer.Change(System.Threading.Timeout.Infinite,EmailInterval);

不够强壮,理论上讲,如果在执行中出错,会执行:

finally{
emailTimer.Change(EmailInterval,EmailInterval);
}


但,事实上,如果是数据库服务器重启,则可以让timer线程永远死掉。

手工解决方法:重启这个webapp

或者改写代码:emailTimer.Change(System.Threading.Timeout.Infinite,EmailInterval);

为:emailTimer.Change(EmailInterval*2,EmailInterval);

可以解决


其他参考:

msdn:

System.Theading.Timer.ChangeAPI:

签名

2008-9-21 16:44:04 顶部
第1页 共页 共0个回复     <<    >>    
 快速回复
  • 支持UBB,HTML标签

  • 高级回复

  • 操作选项:评分 加精 解精 奖惩 设专题 设公告 解公告 固顶 总固顶 解固顶 结帖 解结帖 锁帖 解锁 移帖 删帖
      首页 | 购买指南 | 虚拟主机 | 特色介绍 | 下载中心 | 支付方式
    Copyright 2004-2008 BBSGood.com Powered By: BBSGood.Speed Version 5.0
      咨询电话:0575-85513832、0575-85513825(传真)、7*24小时咨询服务:13606552007 不良信息举报中心 浙ICP备05029817号
      业务QQ:38958768、客服QQ1:415896239、客服QQ2:343896043、MSN:jccsxx@hotmail.com