I developed a WCF web service, one of the methods it has, creates a new entry in the database and also changes the state of an entry in a different table.
What I want to achieve is to reset that change of state after a hour has passed. Hear this example so you can understand what I’m trying to do:
A Device can detect changes which are reported as Events, so a Devices is related to various Events and an Event is related to only one Device. When a new Event is inserted into the database, the Device enters into an alert state, so the state column for that Device is changed to Alert, after 1 hour passes the state column for that Device must return to Normal.
I thought of creating a thread, but I’m new to WCF so I don’t know if that consumes a lot of resources, so I thought of using a Worker Role, but that too stays running the whole time the service is up. At best I want to put any process that would handle this to sleep until a Device’s state changes again, but again, I don’t know if having a thread/worker role sleeping consumes a lot of resources.
How can I achieve this kind of behavior without using much resources?
Don’t use a thread – if the application needs to shut down (deployment, fault, …) the thread is lost and so is the work queued on it. Use a persistent timer service like the Windows Task Scheduler or a lib like Quartz.NET.