How to cancel a background task

When using QueryOp with a progress bar to run a background task, is it possible to cancel the background task?

Your background task needs to be written to handle such a case. Eg if it has a long-running loop, it could check for a ‘abort’ flag set somewhere, and exit early if it is set.