简体   繁体   English

我应该使用辅助角色还是线程来重置数据库中条目的状态?

[英]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.

相关问题 如何使用计时器替换Azure Worker角色中的Thread.Sleep(...)? - How to use a Timer to replace Thread.Sleep(…) in an Azure Worker Role? 我应该使用线程吗? - Should I use a thread for this? 在我的场景中,我应该在WPF和c#中使用哪种类型的线程……常规线程,后台工作程序或线程池? - What type/types of threading should I use in WPF and c# for my scenario… regular threads, background worker, or thread pool? Azure队列工作者角色多线程示例 - Azure Queue Worker Role Multi Thread Example 我如何在工作线程上创建和使用WebBrowser控件? - How might I create and use a WebBrowser control on a worker thread? 我应该使用哪种方法将数据库或目录服务(AD LDS(ldap))用于Windows应用程序(.net)的角色管理?为什么? - Which approach should i use database or directory services (AD LDS(ldap)) for role management a windows application (.net)?And Why? 我应该使用Backround工作者还是编写自己的线程 - Should I use a Backround worker or write my own threads 如何将简单注入器用作Azure Worker角色 - how to use Simple Injector to Azure Worker Role IEnumerable的作用是什么<t>我为什么要使用它?</t> - What's the role of IEnumerable<T> and why should I use it? 我应该使用线程还是线程池进行文件下载 - Should I use Thread or Thread pool for file downloading
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM