240 likes | 397 Views
Offline Detection in SL 3 and .NET Framework. Peter Smith Program Manager, .NET Networking Microsoft Corporation. Why Offline Detection?. Silverlight now has the ability to run from the user’s desktop, just like a normal application
E N D
Offline Detection in SL 3 and .NET Framework Peter Smith Program Manager, .NET Networking Microsoft Corporation
Why Offline Detection? • Silverlight now has the ability to run from the user’s desktop, just like a normal application • Sometimes when your code runs, the user will not be online • You have to detect and handle this case
The One Take-Away Point • How do you know if you are online? • Can you connect to your server? • Have you validated the response? • Microsoft can help by telling you when to try again
demo Demonstration A very simple Silverlight 3 application that does network detection
Why Offline is So Hard • Is the network useful? • Driver issues • Virtual PCs! • Coffee shop problem • Maybe you shouldn’t connect!
The One Take-Away Point • How do you know if you are online? • Can you connect to your server? • Have you validated the response? • Microsoft can help by telling you when to try again
VB.NET Sample • REM function that gets called when the network changes • PrivateSubOnNetworkChange (ByVal s AsObject, _ • ByVal a AsEventArgs) • REM Perform detection here • EndSub • REM set up the system to call that function • PublicSubNew() • AddHandlerNetworkInformation. _ • NetworkChange.NetworkAddressChanged, _ • AddressOfOnNetworkChange • EndSub
C# Sample • privatevoidOnNetworkChange (Object sender, EventArgsArgs) • { • // Put network detection here • } • publicMainPage() • { • NetworkChange.NetworkAddressChanged += • newNetworkAddressChangedEventHandler • (OnNetworkChange); • }
Patterns For Your Code • Ask the user • Before you connect, validate • Constantly validate results
Ask the User • Add two buttons to your application • One is “retry” and tries to connect again • The other is “offline mode” and prevents the application from even trying
Before You Connect, Validate • Put a standard file on your server • Download and check contents • No server==really offline • Revalidate on network change • Got a file from your server, but it’s not yours? You might be have the “coffee shop” problem and must retry
Constantly Check Results • Check all downloads • Not just status code! • No server==really offline • Revalidate on network change • Got a file from your server, but it’s not yours? You might be have the “coffee shop” problem and must retry
The One Take-Away Point • How do you know if you are online? • Can you connect to your server? • Have you validated the response? • Microsoft can help by telling you when to try again
Thank you! Questions? My email is pesmith@microsoft.com NCL (System.Net) blog is http://blogs.msdn.com/ncl/ The team forum is http://social.msdn.microsoft.com/Forums/en-US/ncl/threads/
Please Complete an Evaluation FormYour feedback is important! • Evaluation forms can be found on each chair • Temp Staff at the back of the room have additional evaluation form copies
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Extra Slides! These slides go into more detail about the advantages and disadvantages of the different code patterns for network detection
Advantages of Ask the User • The user might know that they’ve done something special (but undetectable) to go on line • The user might also know that it’s a bad time to go online
Disadvantages to Ask the User • The user might not know that they’ve gone online (and get it wrong) • They also probably think it’s your job normally
Advantages of the Before Pattern • It’s simple • You only have to understand one file (and you can just make it XML)
Disadvantages of "Before" • It’s not always possible to drop a file on your company server • It has an extra bit of work at startup • Sometimes the network changes, but you don’t detect it in time (and ruin a downloaded file)
Advantages of Constantly Check • Starts up faster – no extra file to download • Requires no changes to your server
Disadvantages to Constantly Check • Checking is hard! You have to understand all of the different file types that your application might have • Checking is “noisy”: there are lots of reasons why your server might not have given a good reply