Reputation: 121
I have a .NET web service [WCF hosted in IIS] which now needs to implement a method which would be a long running task.
What is the best practice for this implementation in order to avoid blocking threads from ASP.NET Thread pool?
Moreover Does it make sense to use Task parallel library [TPL] in WCF?
Thanks a lot in advance for your support
Upvotes: 1
Views: 640
Reputation: 171178
Threads in the pool are not really a scarce resource. Unless you plan to consume hundreds at the same time this is not something to worry about.
A long-running background task would be best implemented as a LongRunning
Task
. Be sure to catch any errors so that you know about bugs.
Also note, that background work can disappear at any time when the worker process shuts down (deployment, crash, reboot, ...).
The easiest way to do this would be to not do background work at all. Maybe a client can run a really long running WCF request and you do all of that on the request thread. That handles threading and errors for you.
Upvotes: 2