Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Currently in my Silverlight app I'm polling the database for changes to cached objects and am looking for advice on how to update the views that are displaying these lists.

Example: I have a static class that has lists of objects (Areas, vehicles drivers etc.) that I will be using throughout the application. I have a timer in my shell that will poll the database passing a timestamp of the last update. So if the timestamp has changed the updates will be passed back and the lists will be updated.

How do I update the views that will be displaying these lists. If the user is editing a record that displays a combobox bound to this list how will this data be updated and if the user has made a selection from the list will this affect the selection?

Bear in mind that some users will be adding to these lists that I will be inserting to the database.

Am I going about this in the right way?, or has anybody implemented this with success in their application?

share|improve this question
add comment

migrated from stackoverflow.com Mar 2 '12 at 13:27

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 0 down vote accepted

Using a polling technique combined with Timestamp version test could lead to performance problems in cases with lot of connected clients (>50). If you have a limited number of clients, polling provides a cheap way to do it. In any case, you should always validate the data supplied by the user to ensure that it’s correct. In other words, if the user A deletes an entity and another user B uses the same entity, a validation should through an exception stating that entity is no longer exists.

share|improve this answer
    
Good point Chris - As for not using the polling technique combined with timestamp when there would be a lot of clients connecting. Can you advise on a better way of acheiving this? –  paul Mar 5 '12 at 17:10
    
Depends on the architecture of the application. For example, on WCF service scenarios, if it's possible to use duplex communication, the server could notify the client when an entity changes. –  Chris Mylonas Mar 5 '12 at 19:56
    
I'll have a look into that Chris Thanks. –  paul Mar 6 '12 at 14:31
add comment

You can start by storing the lists in ObserableCollection objects (or one of thew other collection objects designed to notify changes to views) and bind controls in your views to those.

ObservableCollection generate change events when the contents of the list change (additions, deletions etc).

share|improve this answer
    
So if I store the data in the ObservableCollection and update that collection on a background thread (additions, updates etc) would they be automatically updated on the views or do I have to subscribe to the collectionchanged event of the collection and update the list in the views accordingly? –  paul Mar 5 '12 at 17:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.