How to call a service when a SilverLight OOB app is closing an

瘦欲@ 提交于 2019-12-12 04:39:43

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/4010064/how-to-call-a-service-when-a-silverlight-oob-app-is-closing-an

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!