挂起事件中的异步WCF调用 [英] async WCF call in Suspending event

查看:62
本文介绍了挂起事件中的异步WCF调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我刚刚开始开发win8应用程序. Win8应用程序关闭事件不存在,只有暂停事件.我有一个应用程序,当用户关闭该应用程序时,该应用程序应该从数据库中注销.我有一个处理数据库操作的WCF服务.我从暂停事件中调用WCF服务,但它对数据库没有任何影响.如果我从其他任何地方调用它,我肯定可以正常工作.

任何帮助将是巨大的,在此先感谢.

Hy there,

I''ve just started develop apps to win8. Win8 app closing event does not exist, only suspended event. I''ve and app, that should log out from a database, when the user close the app. I have a WCF service that handle the database operations. I call the WCF service from suspending event, but it doesnt make any effect on database. I am sure that this works fine, if i call it from anywhere else.

Any help would be great, thanks in advance.

private async void Current_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
        {
            await service.SetUserOnlineStatusAsync(UserId, 0);
        }

推荐答案

我最近读过类似的文章,但我自己没有尝试过,但是在我看来,运行时可以取消您的操作. br/>
尝试通过请求 SuspendingDeferral来通知您的未完成操作的运行时 [ ^ ]:


I recently read about something similar and i did not try it out myself, but it seems to me like the runtime cancells your operation.

try notifying the runtime of your outstanding operation by requesting a SuspendingDeferral[^]:


private async void Current_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e) {
            var deferral = e.SuspendingOperation.GetDeferral();
            await service.SetUserOnlineStatusAsync(UserId, 0);
            deferral.Complete()
        }



在任何情况下,您都应该意识到,如果暂停的期限已过",则运行时将终止,无论在多大的时间范围内……如果您发现,请让我知道;)



in any case you should be aware that the runtime will terminate anyway, if the "deadline for suspension has passed" - whatever timespan this is...if you find out, let me know ;)


这篇关于挂起事件中的异步WCF调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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