Exercise 2: “Toast” Notifications
In this next stage, we’ll arrange for the application to show “toast” style notifications: small popup windows that appear briefly at the bottom right of the screen. Our administrator dashboard can provide these each time we get any new registrations needing to be acknowledged.
Silverlight 4 does not add any new feature aimed at arranging for this sort of notification to be passed from the server to the client. The focus of this part of the lab is simply the UI mechanism for displaying the notification to the end user. As for the architectural question of how the client knows when to do this, we’ll be using two distinctly lo-tech solutions. To start with we’ll just have a button to show it manually on demand, because that makes it easy to test. Then we’ll make the application poll the server. Every few seconds it will call the operation used in the previous section to fetch the list of unacknowledged items, and when new items appear, we’ll raise a notification.
In general, having a client poll a server every few seconds is not ideal because it does not scale well. In this particular application, we can get away with it because only event administrators will be using this feature, so the feature only needs to scale to however many administrators we have. We probably only have a handful, or maybe even just the one.
Creating the Toast Content
Pop up the Toast
Next, we’ll put code in the view model to raise the notification when it needs to be raised.
Check for Notifications
Next we need to do two things. First, we should check for new data in the timer tick, and second, we should show the notification only if something has changed.