C#中WebService 的 Timer定時器過段時間後自動停止運行

來源:互聯網
上載者:User

標籤:

我用.net做的一個Timer定時器,定時擷取簡訊並給予回複,但大概過了十幾個小時以後,Timer定時器會自動停止,再傳送簡訊就不能收到回複,需要在伺服器中重新運行定時器才可以,請教各位!
我是在.net framework中的,有一個Global.asax全域應用程式檔案,帖代碼:
public class Global : System.Web.HttpApplication
{
double iTimerInterval;
System.Timers.Timer timer = new System.Timers.Timer();
SmsRun smsRun = new SmsRun();
object objLock = new object();
protected void Application_Start(object sender, EventArgs e)
{
//在應用程式啟動時啟動並執行代碼
//在新會話啟動時啟動並執行代碼
SetAccount();
timer.Start();//定時器開始
}

protected void Application_End(object sender, EventArgs e)
{
timer.Stop();
}

private void SetAccount()
{
double.TryParse(ConfigurationManager.AppSettings["TimerInterval"], out iTimerInterval);
timer.Interval = iTimerInterval;
timer.Elapsed += new System.Timers.ElapsedEventHandler(getMessage);
//getMessage是個方法(略)
}



提問者採納: 
有可能是由於timer已經被回收掉了 你是在什麼環境下面winform? webform? 

經過你的補充我看明白了 是這樣的 由於你的應用程式在特定空閑時間之後相應的w3wp輔助進程會被回收掉 所以你的timer自然沒有作用了 你可以查看iis 應用程式集區的屬性 切換到效能選項卡空閑逾時 預設的時間是20分鐘 也就是說如果20分鐘內你的網站沒有任何請求那麼就會造成回收


-----------------------------------------------------------
:

 

C#中WebService 的 Timer定時器過段時間後自動停止運行

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.