“在此上下文中不允许异步操作” [英] "Asynchronous operations are not allowed in this context"

查看:170
本文介绍了“在此上下文中不允许异步操作”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调用他自动生成异步web方法时,我得到下面的异常,我在这篇文章

I get the exception below when invoking he automagically generated async webmethods that i asked about in this post


在此上下文中不允许异步操作。页面起始
异步操作必须将Async属性设置为true
,异步操作只能在

Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to

$ b $之前的页面上启动b

Google搜索结果在页面指令中添加 Async = True ,但各种人士都注意到,这使得页面'阻止' / strong>(这不是真正的异步操作)。那么在调用webservice方法的时候如何实现异步操作。

Google search results in add Async = True in the page directive but various people have noted that this makes the page 'Blocking' (which isn't true asynchronous operation). So how do i achieve asynchronous operation while calling webservice methods.

推荐答案

查看这个答案。我不会从那里复制/粘贴答案,但我会扩大讨论范围。

Check out this answer. I won't copy/paste the answers from there but I'll extend the discussion some.

接受的答案是不正确的。由于没有EndInvoke,因此每次调用此方法时都会出现资源泄漏。 看到这个讨论,为什么不行

The accepted answer is NOT the correct one. Since there is no 'EndInvoke' there will be a resource leak every time this method is invoked. See this discussion on why that's not okay.

相反,建议启动守护进程线程或创建从MSMQ读取的完整的不同进程,并处理那些长时间运行的任务。

What is suggested instead is to launch either a daemon thread or create whole different processes that reads from MSMQ and processes the long-running tasks there.

这篇关于“在此上下文中不允许异步操作”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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