SilverLight OOB 应用程序关闭时如何调用服务 [英] How to call a service when a SilverLight OOB app is closing an

查看:35
本文介绍了SilverLight OOB 应用程序关闭时如何调用服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的 SilverLight 应用程序退出时,我需要调用 WCF 服务进行更新.这是一个浏览器外的应用程序,我使用的是 SL4.

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.

由于 SL 中的 WCF 只能异步工作,因此不可能在 Application.Exit 上执行

Since the WCF in SL works only async it is not possible to do on Application.Exit

我也试过 MainWindow.Closing 可用于 OOB 但这也不起作用.

I tried also MainWindow.Closing which is available for OOB but this didn't work either.

尝试使用线程锁定使 Closing 函数等待 WCF Completed 回调,但它只是挂起.

Tried to make the Closing function wait for the WCF Completed callback using thread locking but it just hang.

有什么想法吗?

沙哈尔

推荐答案

保存数据并在下次启动时提交

无论您在哪个平台上,在退出时调用服务都是一项棘手的功能.您不能真正保证这会发生,因为您的进程可能会因各种原因(任务管理器、logff、关机、蓝屏等)在您调用之前退出.如果您正在编写重要数据(例如系列中的最后一条记录),您充其量只能看到部分数据集,而最坏的情况是损坏的数据.

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.

最好将所有服务器通信都作为一次性事务进行.如果您在退出时提交的数据用于日志记录或指标目的(例如应用程序运行了多长时间,'foo' 被调用了多少次),更好的模式是持续将数据保存到磁盘,然后进行计算和运算;下次启动应用程序时提交数据.

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.

这篇关于SilverLight OOB 应用程序关闭时如何调用服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆