Exactly this degree of randomness consistent with a non-deterministic behavior makes my hair turn white. It's a Windows service that runs a scheduled Quartz.NET job each morning.
This service runs under a specific domain user who is also a root admin in QS. Now, this job iterates over a list of values and apply each of the list's value as a QS selection on that specific field and exports the data behind a table object as an Excel file.
Now I may have a clue: sometimes there's someone else, another user, who logs in with the same username as the service.
Is it possible if one opens a QS session with the same username to mess up the running job?
I'm speculating it would mess up the outputs of either the exported Excel file or the user's selections in the QS GUI, but it would not hang the entire execution.
Anyhow, I will wrap your nice suggestion for a cancel-able function with a retry policy and I will come back with a feedback.
Another user could certainly affect the results of the selection if that user connects to the same engine session as your service. You should make sure to use a unique session for the service when you connect to the engine. Something like this: