zoukankan      html  css  js  c++  java
  • C#中WebService 的 Timer定时器过段时间后自动停止运行

    我用.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分钟内你的网站没有任何请求那么就会造成回收


    -----------------------------------------------------------
    截图:
    
    
  • 相关阅读:
    Spring学习总结之高级装配
    Spring学习总结之装配bean
    NS2安装过程中环境变量设置的问题(ns-2.35)
    =======================分割线======================================
    java的内存管理机制
    Python之面向对象编程
    Python之列表生成式
    Python之函数的参数
    Git基础级介绍
    第四次作业——个人作业——软件案例分析
  • 原文地址:https://www.cnblogs.com/zouhao/p/4246801.html
Copyright © 2011-2022 走看看