Timer doesn't work on WinHost?

Discussion in 'General troubleshooting' started by mjsw, Dec 26, 2009.

  1. Hello,

    I have another problem. I'm playing a bit with Timer class and I wrote simple service that keeps doing "something" every 5 seconds:

    Code:
    public class BackgroundService : IHttpModule
        {
            static Timer timer;
            int interval = 5000;
            public String ModuleName
            {
                get { return "BackgroundService"; }
            }
    
            public void Init(HttpApplication application)
            {
                 if(timer == null)
                    timer = new Timer(new TimerCallback(ScheduledWorkCallback), application.Context, interval, interval);
            }
    
            public void Dispose()
            {
                timer = null;
            }
    
            private void ScheduledWorkCallback(object sender)
            {
                HttpContext context = (HttpContext)sender;
                DoSomething(context);
            }
    
            void DoSomething(HttpContext context)
            {
                Log.Entry("I'm your service");
            }
        }
    and in web config:
    Code:
    <httpModules>
    <add name="BackgroundService" type="Namespace1.BackgroundService" />
    </httpModules>
    in this case it's writing some string to my log. It works on my localhost server (this means it keeps updating the log every 5 secs) but it doesn't on Winhost server. Anyone can tell me why? What is causing it?

    I get no error and my log is not updated, while on localhost it is being updated with that string...
     
    Last edited by a moderator: Oct 14, 2015
  2. Nevermind, Ive resolved it myself.

    If anyone is interested here is solution: http://msdn.microsoft.com/en-us/library/ms227673.aspx - IIS7.0 in Integrated mode uses

    Code:
    <system.webServer>
        <modules>
          <add name="HelloWorldModule" type="HelloWorldModule"/>
        </modules>
      </system.webServer>
    instead of
    <system.web>
    <httpModules>
     
  3. Ray

    Ray

    Thanks for the posting. I myself haven't tried this but its good to know I now have a reference to call on.
     

Share This Page