Polled idle state task becomes completed state task, successful or not?

I’m changing the storage for a device, using InvokeMethod(ConfigurationItem, methodId). It returns a task item that has the state “Idle”. When polling the task, its state has become Completed.

When I check my recording server in the Management Client, I see that the device had its storage changed, so the task completed successfully. But how can I check that in the code if the task’s state goes straight from Idle to Completed? Is a completed task always to be considered successfully completed?

Update: The ConfigApiClient example also doesn’t seem to handle task Complete state. The timer that polls for task completion will run forever, since it only checks for Success/Error task state, not Completed:

Actually the task is automatically cleaned up after completion if it goes well, so that is why you just get a message saying that it is completed. If it were not succesfull the task would still be around and you would be able to read the error from it. That said, we looked a bit into this specific method and it seems very unlikely that it will be able to fail after being started. The only error scenarios we could come up with causes the InvokeMethod to throw an exception right away.

Thanks for letting us know about the issue with the ConfigApiClient sample - we will make sure it is fixed for the 2023 R3 release.

Hi!

So a task that returns in Complete state after a method invoke can be considered a successful task? Thanks for clearing that up.

How long do tasks that return in Error state stay in that state? Do they get automatically cleaned up after a while or does it have to be queued for cleanup by my code? What is their final state?

Thanks.

Tasks in error state will stay so until they are cleaned up. The error state is the final state.