文章分类 | 软件分类 | 最新软件 | 杀毒软件 | 实用软件  | MTV下载  | 设为首页 |
  | 下载分类 | 最近更新
您的位置: 首页 >> 文章首页 >> 技术开发 >> .Net 专栏 >> ASP.NET技巧 >>  
ASP.NET技巧点击TOP10
·ASP.NET 2.0中使用自定义provider2006-2-10 12:49:07
·灵活正确的实现.NET插件机制2006-2-10 12:42:54
·asp.net如何生成图片验证码(简单)2006-2-10 12:24:18
·如何保证web app中的Send Email线程稳定性2006-2-10 12:00:59
·.NET环境下几种不同的邮件发送解决方案2006-2-10 12:00:59
·如何获取当前程序文件的路径 Current Path2006-2-10 12:46:13
·在Asp.net中为图像加入版权信息2006-2-10 12:42:56
·关于用ASP.Net识别远程主机服务器种类2006-2-10 12:02:36
·web中,如何读取Word内容(包含表格,但不包含图片)并且显示在页面中或保存进数据库中2006-2-10 12:00:57
·asp.net开发wap程序必备:识别来访手机品牌型号2006-2-10 12:46:17
.Net 专栏点击TOP10
·ADO.net中数据库连接方式2006-2-9 17:35:03
·ASP.NET里的事务处理2006-2-5 12:41:30
·使用Web服务将C#代码转换为VB.NET代码2006-2-9 18:10:39
·十天学会ASP.net之第九天2006-2-6 10:10:06
·如何给DataGrid添加双题头分类显示2006-2-5 18:46:43
·使用嵌套的Repeater控件2006-2-5 12:41:52
·Net 下安装、调试的常见问题与错误2006-2-9 9:04:53
·在ASP.NET中值得注意的两个地方2006-2-9 16:40:07
·C#中的非安全编程2006-2-9 17:32:38
·ASP.NET中利用cookies保持客户端信息2006-2-9 17:33:25

 

如何保证web app中的Send Email线程稳定性
作者:我去下载           时间:2006-2-10 12:00:59


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

会导致Send Email 线程死掉。

参考代码:
private void ScheduledWorkCallbackEmailInterval (object sender)
{
   try {
    // suspend the timer while we process emails
    emailTimer.Change( System.Threading.Timeout.Infinite, EmailInterval );

    // Send emails
    //
    Emails.SendQueuedEmails( (HttpContext) sender);


    // Update anonymous users
    //
    Users.UpdateAnonymousUsers( (HttpContext) sender);

   }
   catch( Exception e ) {
    ForumException fe = new ForumException( ForumExceptionType.EmailUnableToSend, "Scheduled Worker Thread failed.", e );
    fe.Log();
   }
   finally {
    emailTimer.Change( EmailInterval, EmailInterval );
   }
        }

 

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

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

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


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

手工解决方法:  重启这个web app

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

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

可以解决


其他参考:

msdn:

System.Theading.Timer.Change API:

分页:
相关文章:
Copyright© 2005-2006 wqxz.com, All Rights Reserved. 购买虚拟主机请与本站联系