views:

24

answers:

1

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 it 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

A: 

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.

Jay
Thanks for the answer but I need to notify the server and other applications that my SL app closed synchronously. For example I have a duplex port opened to push updates to the client and I need to know to remove clients that closed from the updates list.
Shahar
On the server remove broken connections upon discovering them when pushing an update. Your notification upon shutdown technique isn't going to work reliably.
Jay