for a task, potentially taking too long to complete, I’d like a mechanism
- to start the task
- return back to user interface (its a web page)
- periodically/randomly check if the task is complete
- cancel the executing task when user wishes so
- get notified when the task completes / fails
what are the possible solutions?
-
Threads?
Start a thread, save its ManagedThreadId, (can you get a thread by its id) -
write a windows service,
send the request to service via shared objects/files/db?
keep interacting with the service the same way (objects/files/db,etc)
Services?
Host a WCF Service in a Windows Service that will perform the background tasks by adding/reading from a queue which can be maintained either using MSMQ or in a database.
When you add an item for processing; you should get a task id. You should be able to then log the completion/failed/cancel status of the task in db against the task id.
You can have following methods in your WCF contract