I need to call a WCF service to update when my SilverLight app exits. it is an out-of-browser app and I'm using SL4.
Since the WCF in SL works only async i开发者_开发问答t is not possible to do on Application.Exit
I tried also MainWindow.Closing which is available for OOB but this didn't work either.
Tried to make the Closing function wait for the WCF Completed callback using thread locking but it just hang.
Any ideas?
Shahar
Save the data and submit on next launch
Calling a service on exit is a tricky feature no matter what platform you are on. You can't really guarantee that this will happen because your process might exit before your call is made for any number of reasons (task manager, logff, shutdown, bluescreen, etc). If you're writing important data such as the last record in a series, you're opening yourself to partial datasets at best and corrupted data at worst.
It's better to do all your server communications as lump transactions. If the data you're submitting on exit is for logging or metrics purposes (e.g. how long did the app run, how many times did 'foo' get called) the better pattern is to continuously save your data to disk and then do calculations & submit the data the next time the application is launched.
精彩评论