简体   繁体   English

从Windows Service收听事件

[英]Listening To Events from windows Service

Sorry if it is a basic question but I am new to Database polling 抱歉,这是一个基本问题,但是我是数据库轮询的新手

I am creating an ASP.net project in which we need to constantly monitors a database (MySQL) table and whenever any row is added in that table, we display that in UI. 我正在创建一个ASP.net项目,在该项目中我们需要不断监视数据库(MySQL)表,并且每当在该表中添加任何行时,我们都将其显示在UI中。 Now I have created a Windows Service which monitors that DB table and it generates an event when the table changes. 现在,我创建了一个Windows服务,该服务监视该数据库表,并在表更改时生成一个事件。 Now How can get that notification in my ASP.net project from my windows service so that I can display in UI? 现在如何从Windows服务中的ASP.net项目中获取该通知,以便可以在UI中显示?

I would get rid of the Windows service and implement the polling in the ASP.NET website itself. 我将摆脱Windows服务,并在ASP.NET网站本身中实现轮询。 You said that you only want to show the new records on the website UI, so there's no reason for a service, which only introduces an unnecessary communication layer. 您说过,您只想在网站UI上显示新记录,因此没有必要提供服务,因为这只会引入不必要的通信层。 You need to have your website constantly running anyway to do what you want, so you don't need that advantage of Windows services, which are generally used to keep stuff running. 无论如何,您都需要使网站持续运行以执行所需的操作,因此您不需要Windows服务的这种优势,Windows服务通常用于使内容保持运行。

Just make sure that your ASP.NET website is constantly running ( startMode = AlwaysRunning ) and has no idle timeout ( processModel.idleTimeout = TimeSpan.Zero ). 只要确保您的ASP.NET网站不断运行( startMode = AlwaysRunning )并且没有空闲超时( processModel.idleTimeout = TimeSpan.Zero )。 I would use SignalR for the push notifications, so whenever you find a new row, you can send a message to clients and they can react to that immediately. 我将SignalR用于推送通知,因此,无论何时找到新行,都可以向客户端发送消息,他们可以立即对此做出反应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM