国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

如何保證web app中的Send Email線程穩定性

2019-11-18 19:15:18
字體:
來源:轉載
供稿:網友

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:


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乌鲁木齐县| 高青县| 玉龙| 措勤县| 夹江县| 武鸣县| 赤水市| 禹州市| 太原市| 华池县| 英山县| 左云县| 如皋市| 龙海市| 永丰县| 绩溪县| 大宁县| 桃园县| 界首市| 肃北| 柯坪县| 虞城县| 穆棱市| 体育| 广德县| 古浪县| 潍坊市| 宁都县| 徐水县| 哈尔滨市| 林州市| 青川县| 安多县| 白河县| 林芝县| 黑山县| 平果县| 历史| 太康县| 长顺县| 金昌市|