Reputation: 117
I'm trying to develop a very simple messaging form (MVC C# forms), in which a form displays how many unread messages a user has. If a new message was to come into the list in my model, how do you notify the view (which methods)? I can't seem to get my head round this.
Upvotes: 1
Views: 2224
Reputation: 10886
If you are talking about a C# windows forms application then what you want to use is the Observer pattern. See here for the pattern. Basically you want to have your controller register with the model via the observer pattern to be notified of any model changes that can cause the view to be obsolete. Then the controller can notify the view to re render the affected portion.
Upvotes: 1
Reputation: 6830
Ideally, you require some kind of push technology, since in your scenario the server initiates the update.
I would suggest two possible solutions:
If you anticipate more and more information you will need to refresh in the future, I would definitely vote for SignalR as it will make your code much more maintainable.
Upvotes: 2