QAction calls an async method and gets stuck. I tried canceling the async method using timeout and CancellationToken, but the QAction is still on the stack. Is there any way I can remove it from the stack?
Hi Elmaza,
There's no immediate way to abort a specific thread, however, have you tried to either:
- Stop or restart the element?
- If it isn't a production system, or the impact of reloading the data kept in scripting, you can kill the SLScripting process. It's one of the few processes that DataMiner will simply restart without restarting the agent.
- Your last option is to restart the agent if this thread really needs to get off the stack and killing SLScripting would be too abrupt.
You may want to stop the element while the agent is down to avoid it entering into the same state again, for that, we have the Change Element States Offline tool.
Do you require any assistance with the implementation of the async method?
Hi Elmaza,
I assume the problem you face will stem from the fact that a QAction’s Run method is not async itself.
Is your async method expected to return data as soon as possible, or is listening for a potential client to connect for example? For the latter case, you’ll want to offload your call to a separate thread I believe.
If you’re int he first case however, then I believe the approach would be to not use “await”, grab the task and wait on said task using your cancellation token. Do note that to cancel the token, you can’t just use a different trigger as the main thread will still be stuck waiting. You should either set your token to expire after a certain time, or let it run on a separate thread, so your Main function can be called to set the token.
Note that if you create threads, you may want to implement the dispose (https://docs.dataminer.services/develop/devguide/Connector/LogicQActions.html#implementing-the-idisposable-interface) to cancel the token when the element stops too.
As a follow-up, the Ember+ library has a lot of async functions, even though it expects everything to be executed from a single thread using their AsyncPump class. What we’re trying now is to launch this pump on a separate thread using a task that we can kill if it gets stuck, also using a CancellationToken.
Hi Floris,
Thank you for the answer.
The stack is cleared when the element is stopped, but this is repeated after each activation of the element.
I’m trying to find a way to avoid that QAction gets stuck. The async method being called is part of the Ember+ library.