Mike Flynn
Mike Flynn

Reputation: 24325

ASP.NET Web Service call in another Thread

We are making a web service call on some data updates to sync another database. This web service call takes up some response time. Would adding it in a thread help at all? Any downfalls of doing this? If the web service calls fails, it fails and that is it. It is like a fire and forget call.

Upvotes: 3

Views: 2310

Answers (4)

Bhuvan
Bhuvan

Reputation: 1573

I strongly advice against using Async Web Service calls (including making calls in separate threads) from a web app. Instead use alternate approach like Ajax, and make this webservice call from an Ajax Call instance. There is no easy approach in the web context to handle threading and Async calls.

Upvotes: 0

George Johnston
George Johnston

Reputation: 32258

You could use an Asynchronous Web Service call using asyncronous callbacks to prevent blocking of your main thread.

By making an asynchronous call to a Web service, you can continue to use the calling thread while you wait for the Web service to respond. This means users can continue to interact with your application without it locking up while the Web service access proceeds.

From MSDN: Making Asynchronous Web Service Calls

Upvotes: 2

TehBoyan
TehBoyan

Reputation: 6890

In addition to Tudor's answer I would suggest that you start off by using the new Task class from .NET 4.0.from task parallel library. Example would be:

Task backgroundProcess = new Task(() =>
{
     service.CallMethod();
});

Upvotes: 2

Tudor
Tudor

Reputation: 62439

If it's taking long enough to hang the user interface then calling it on another thread is the recommended thing to do.

Upvotes: 2

Related Questions