user2740190
user2740190

Reputation:

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. I did some search on the website and found this solution for Async calls:

 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. Thanks for suggestions.

Upvotes: 1

Views: 1300

Answers (1)

usr
usr

Reputation: 171178

Can you tolerate the logging work to be lost? Only then should you start "background work" in an ASP.NET app.

QueueUserWorkItem will work. The more modern version is 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. It does not use any thread while in progress (not even a background thread).

Upvotes: 2

Related Questions