如何在 SilverLight OOB 应用程序关闭时调用服务
当我的 SilverLight 应用程序退出时,我需要调用 WCF 服务进行更新。 它是一个浏览器外应用程序,我使用的是 SL4。
由于 SL 中的 WCF 仅异步工作,因此无法在 Application.Exit 上执行此操作,
我还尝试了可用于 OOB 的 MainWindow.Closing,但这也不起作用。
尝试使用线程锁定使 Closing 函数等待 WCF Completed 回调,但它只是挂起。
有什么想法吗?
沙哈尔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
保存数据并在下次启动时提交
无论您使用哪个平台,退出时调用服务都是一项棘手的功能。您不能真正保证这种情况会发生,因为您的进程可能会因多种原因(任务管理器、logff、关闭、蓝屏等)在调用之前退出。如果您正在写入重要数据,例如系列中的最后一条记录,那么您最多只能看到部分数据集,最坏的情况就是损坏数据。
最好将所有服务器通信作为批量事务进行。如果您在退出时提交的数据用于记录或指标目的(例如应用程序运行了多长时间,“foo”被调用了多少次),更好的模式是将数据持续保存到磁盘,然后进行计算和计算;下次启动应用程序时提交数据。
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.