[英]Should I use a Worker Role or a Thread to reset the states of an entry in the database?
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. 我开发了WCF Web服务,它是其中的一种方法,它在数据库中创建了一个新条目,还更改了其他表中条目的状态。
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 .
将新的事件插入数据库后,设备将进入警报状态,因此该设备的状态列更改为警报 ,经过1小时后,该设备的状态列必须返回正常 。
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. 我曾想创建一个线程,但是我是WCF的新手,所以我不知道它是否消耗很多资源,所以我想到了使用Worker角色,但是在整个服务启动期间它仍然保持运行。 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.
使用持久性计时器服务(例如Windows Task Scheduler)或库(例如Quartz.NET)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.