[英]Best way to observe changes to SQL table or query in c#
I have the following repository method... 我有以下存储库方法...
IEnumerable<Client> repo.GetActiveClients();
What is the best way to periodically call this method and observe changes to the resulting enumerable list? 定期调用此方法并观察结果枚举列表的更改的最佳方法是什么?
I am aware that RX provides .ToObservable()
, which simplifies responding to changes in collection through subscriptions, but from examples I've seen, I can't work out how best to handle the polling and periodic calling of the method which will change the contents on the collection in the first place? 我知道RX提供了
.ToObservable()
,它简化了通过订阅对集合中的更改的响应,但是从我看到的示例中,我无法弄清楚如何最好地处理将要更改的方法的轮询和定期调用首先放在收藏的内容上?
Unless I'm missing something in your question, I think this is the best option: 除非我在您的问题中遗漏任何东西,否则我认为这是最好的选择:
IDisposable subscription =
Observable
.Interval(TimeSpan.FromSeconds(15.0))
.Select(x => repo.GetActiveClients())
.Subscribe(clients =>
{
/* do something with the `clients` */
});
Simple. 简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.