同一控制器中的异步和同步操作方法
AsyncController
中可以有异步和同步操作方法吗?这样做有什么缺点吗?
原因是异步操作对于耗时的操作有意义,但对于返回 HTML 表单没有意义。
例如,我有一个生成文件的页面。返回带有输入的表单的操作方法几乎没有逻辑,但是接收 POST、将其发送到另一个 Web 服务并中继响应的操作方法需要一些时间,因此异步执行此操作是有意义的。
我可以将这些方法放在单独的控制器中,一个同步,另一个同步,但我想将它们放在一起。
干杯。
Is possible to have asynchronous and synchronous action methods in an AsyncController
? Is there any drawback doing this?
The reason is that an asynchronous operation makes sense for a time consuming operation, but does not make sense for return a form in HTML.
For example, I have a page that generates a file. The action method that returns the form with the inputs has almost no logic, but the action method that receives the POST, send it to another web service and relay the response takes some time, so it will make sense to do it asynchronously.
I could put those methods in separated controllers, one synchronous and another synchronous, but I would like to keep them together.
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。
并不真地。
耗时的操作和 I/O 密集型来说是有意义的,这样您就可以从 I/O 完成端口中受益。如果您有一个在单独线程中运行的耗时 CPU 操作,那么异步控制器绝对不会给您带来任何好处。相反,它会让事情变得更糟。
OK,Web服务调用是一个I/O密集型操作=>您将从异步控制器中受益。在这种情况下,您可以在同一个异步控制器上执行这两个操作。
Yes.
Not really.
time consuming operation and I/O intensive so that you can benefit from I/O Completion Ports. If you have a CPU time consuming operation that you are running in a separate thread you get strictly no benefit from async controllers. At the contrary it will make things worse.
OK, web service call is an I/O intensive operation => you will get benefit from an async controller. You could have the two actions in this case on the same async controller.