I don't know about a safe way to interrupt a thread.
The background worker can check if he should cancel and cancel himself, but if he does not request a database, you cannot make it until it returns.
You can work on a ThreadPool thread and just drop the thread and start another if it is no longer needed (make sure that when it comes back from the db request, it checks to cancel it before doing anything unpleasant). Of course, you need to balance performance and manage thread synchronization. If you go down this path, you can take a look at the static Interlocked class to effectively lock the critical section.
AndrewS
source share