Take a .Net Winforms App.. mix in a flakey wireless network connection, stir with a few users who like to simply pull the blue plug out occasionally and for good measure, add a Systems Admin that decides to reboot the SQL server box without warning now and again just to keep everyone on their toes.
What are the suggestions and strategies for handling this sort of scenario in respect to :
-
Error Handling – for example, do you wrap every call to the server with a Try/Catch or do you rely on some form of Generic Error Handling to manage this? If so what does it look like?
-
Application Management – for example, do you disable the app and not allow users to interact with it until a connection is detected again? What would you do?
Answer depends on type of your application. There are applications that can work offline – Microsoft Outlook for example. Such applications doesn’t treat connectivity exceptions as critical, they can save your work locally and synchronize it later. Another applications such as online games will treat communication problem as critical exception and will quit if connection gets lost.
As of error handling, I think that you should control exceptions on all layers rather than relying on some general exception handling piece of code. Your business layer should understand what happened on lower layer (data access layer in our case) and respond correspondingly. Connection lost should not be treated as unexpected exception in my opinion. For good practices of exceptions management I recommend to take a look at Exception Handling Application Block.
Concerning application behavior, you should answer yourself on the following question ‘Does my application have business value for customer in disconnected state?’ In many cases it would be beneficial to end user to be able to continues their work in disconnected state. However such behavior tremendously hard to implement.
Especially for your scenario Microsoft developed Disconnected Service Agent Application Block