Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I'd like your opinion on something. I have the following class:

public class ApplicationClock
{
    void tick(object _)
    {
        lock (tickLock)
        {
            try
            {
                MessageBroker.Publisher.Publish(new Tick());
            }
            catch (Exception e)
            {
                this.Logger().Error("Application clock tick error", e);
                //who knows why this happened, let's try and restart
                if (ticker != null) ticker.Dispose();
                Start();
            }
        }
    }
    readonly Object tickLock = new Object();
    Timer ticker = null;
    public ApplicationClock Start()
    {
        ticker = new Timer(tick, null, 0, 60*1000);
        return this;
    }
}

launched from the MvcApplication bootstrapper

...
ApplicationClock clock;
protected void Application_Start() 
{
   //...
   clock = new ApplicationClock().Start();
}

I realize that a service and some sort of inter-process communication (whether windows inter-process communication, HTTP, or something else) is more standard and reliable but I have a frequently changing team and don't want to add another step that is necessary to run the app.

This seems to work but I've only launched it in a dev scenario. Am I missing anything that would cause problems in production?

That's a System.Threading.Timer by the way.

share|improve this question
If it's launched from the bootstrapper and there is only ever one instance launched at app start is there any need to provide locking? – dreza Sep 7 '12 at 19:27
@dreza - just a precaution if it is in the process of crashing and restarts, or if a tick takes longer than a minute for some reason. – George Mauer Sep 7 '12 at 19:58
Why exactly are you even trying to do this? Also... The System.Diagnostics.Stopwatch class is great for measuring time taken. – Jeremy Bell Sep 8 '12 at 0:06

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.