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)
精彩评论