1

I have a web service, which takes lot of time to execute. I am planning to delegate the processing task to a background thread & return the acknowledgement response to the user immediately.

In this case I was worried about the life-time of the background thread.
Will background thread complete the delegated task, before main method/thread finishes execution?

Abhijeet
  • 13,562
  • 26
  • 94
  • 175
  • "web service method must have returned the value" , which value? the value from your background thread? You said ur background thread will run a BIG task, why you want to wait for its finishing? – ValidfroM Jul 31 '13 at 10:55
  • Or alternatively, just implement an asynchronous call, which is more simple IMO – ValidfroM Jul 31 '13 at 11:03

2 Answers2

0

Looks like your background thread might get aborted if the app pool gets recycled. Have a look at this article ThreadPool.QueueUserWorkItem in Web Service for “Fire and Forget” task

Community
  • 1
  • 1
NeddySpaghetti
  • 13,187
  • 5
  • 32
  • 61
0

You should call your service asynchronously.

var service = new YouServiceClient();
service.SomeMethodCompleted +=
  (sender, args) +=
  {
    //  Put code here to handle the response and extract a return value or whatever.
  }
service.SomeMethodAsync();

Refer to How to: Call WCF Service Operations Asynchronously for more details.

Brian Gideon
  • 47,849
  • 13
  • 107
  • 150