开发者

Silverlight and M-V-VM - Where should a timer live?

开发者 https://www.devze.com 2023-01-03 12:05 出处:网络
I\'m creating a simple monitoring tool in Silverlight. It talks to a web service to retrieve the status information and store it in the ViewModel. This needs to happen once per minute so I\'m going to

I'm creating a simple monitoring tool in Silverlight. It talks to a web service to retrieve the status information and store it in the ViewModel. This needs to happen once per minute so I'm going to add a timer for this purpose (probably a DispatcherTimer).

My question开发者_开发技巧 is, where should the timer go in an M-V-VM architecture? In the ViewModel or the View?


If you don't have a model then next best thing is to put timer (Observable.Timer would be much easier to use) into ViewModel. E.g. something like this:

Observable
    .Timer(TimeSpan.Zero, TimeSpan.FromMinutes(1))
    .SelectMany(_ => GetDataFromWebService())
    .Subscribe(UpdateViewModel)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号