简体   繁体   English

ASMX Web服务的异步调用

[英]Async call of ASMX web service

In my scenario when ever user changes some fields in the program and does a SAVE , a webserivce request is sent to save some logging information into the database. 在我的场景中,当用户更改程序中的某些字段并执行SAVE ,将发送一个webserivce请求以将一些日志记录信息保存到数据库中。 I did some search on the website and found this solution for Async calls: 我在网站上进行了一些搜索,找到了用于Async调用的此解决方案:

 ThreadPool.QueueUserWorkItem(delegate
 {
    // Create an instance of my webservice object.
    // call its Log webmethod.
 });

But since I don't have much experience with webservices and Async calls so I wanted to show you the scenario I have and the way I am handling it to get your opinion about it and if it the right way to do this. 但是由于我对webservicesAsync调用没有太多的经验,所以我想向您展示我所遇到的情况以及我处理它的方式,以征询您的意见,以及这样做是否正确。 Thanks for suggestions. 感谢您的建议。

Can you tolerate the logging work to be lost? 您可以容忍日志工作丢失吗? Only then should you start "background work" in an ASP.NET app. 只有这样,您才应该在ASP.NET应用程序中开始“后台工作”。

QueueUserWorkItem will work. QueueUserWorkItem将起作用。 The more modern version is Task.Run . 更现代的版本是Task.Run Make sure you catch errors that happen on that thread-pool thread. 确保捕获该线程池线程上发生的错误。 If not, you'll never find out about bugs and silently lose work. 如果没有,您将永远不会发现错误,并且会默默地丢失工作。

If you expect a high volume of such calls, or expect them to take a long time, consider using async IO . 如果您期望大量此类调用,或者期望它们花费很长时间,请考虑使用异步IO It does not use any thread while in progress (not even a background thread). 在执行过程中,它不使用任何线程(甚至不使用后台线程)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM