views:

33

answers:

1

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?

A: 

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)
PL
Thanks, I'll give it a go. Didn't know about Observable.Timer (I'm really new to Silverlight).
Bill Jeeves
Observable is part of the new Reactive Extensions framework and imho is revolutionary. You can check it out at: http://msdn.microsoft.com/en-us/devlabs/ee794896.aspx
Przemek