My process is as follows:
- User logs into web app and this drops an entry into the UserQueue table
- A Windows Service polls this table every x seconds and processes each item
- Once processed the item is deleted from the UserQueue table
This all works well with sequential processing but I'm concerned that a long-running task could block the queue for all other users (and this would be an issue for the web app).
I considered the BlockingCollection in .NET to hold the items in memory and then process them but I cannot guarantee that a row from the UserQueue table won't get put into that collection more than once (due to the non-unique nature of BlockingCollection) unless I use a database flag (BeingProcessed = true for example). I'm not keen on a database flag because if my service was stopped for any reason it could leave unprocessed items in the table with the BeingProcessed = true.
Is there a more standard approach to this that I am missing or should I consider Quartz.net or similar?