views:

182

answers:

2

Hi,

I am wanting to write some web services using WCF.

I would like to have a "thread pool" in my web service. For example, I have nearly 6gb of data I need to manipulate.

I would like the client to call an operation on the webservice and have a new task or thread created. The client is able to call a ListRunningTasks(); and have the webservice return a list of tasks. The client should be able to forcefully kill a task if it is taking too long e.g. KillTask(int taskID); or something. I have previously done some threading, but not inside WCF or a service that doesn't have state. Is this possible? If so, how would one go about implementing such a thing? Any reading, links or suggestions would be great.

Thanks, Mike.

A: 

You should consider using Windows Workflow Foundation to create such services. A state machine workflow can be exposed as a service in such a way that when method A is called, it will start the workflow (task), after which methods can be called to stop, suspend, or query the running task. WF will handle the state transitions, preventing illegal state changes, and making sure that new tasks are only spun up as necessary.

Note that WF will handle the threading issues for you in an almost transparent manner.

John Saunders
Thank you John, this sounds interesting. I will check it out this afternoon. Thanks again!
Mike
A: 

One possible solution:

  • Implement explicit queues for your outstanding tasks taking into consideration that they take that long (20-30mins as you wrote).

  • Build a custom component to manage those queues e.g. you might even want capabilities to persist them, resume work when you restart the service etc.

  • Have explicitly created worker threads that pickup work from those queues.

  • Implement a WCF service to make your queue manager available to external systems.

Thread pools are more designed to process a high volume of short-running tasks.

Alex
As John wrote, this can be accomplished by WWF. However, depending on your task, WWF might be a bit overkill.
Alex
The main thing which I don't know how to do is handling the state. WCF is stateless. What is an explicit queue? is that a .Net thing? I can't find anything about that. How can this queue have state? Thanks for your answer Alex
Mike
"What is an explicit queue" - just an object that stores your outstanding tasks. Explicit meaning that you create a manage that queue on your own. WCF is stateless but that doesn't mean that your whole process has to be stateless.
Alex