I am trying to create a Command subclass which listens for an interrupt to cancel the command. When cancelling the command, I have tried using the Cancel() method, but it fails when the command is part of a CommandGroup. Is there a universal way to forcibly end a command from within the command itself?
EDIT: Also, can the Cancel() method be used on a CommandGroup object? If so, I could work around this issue.
I have a background thread that checks for a certain button combination on the joystick being pressed. The Cancel() method will be called when that condition is true.
The hardware generates an electrical signal (called an interrupt) that causes the CPU to stop what it’s doing, save its “context”, jump to a new location in program memory, and start executing there. That location is called an ISR – interrupt service routine. When the ISR is done executing, it tells the CPU to go back to where it was when the interrupt occurred. The CPU uses the saved “context” to go back to where it was, as it was.
You can see there is no polling involved. That’s the advantage of interrupts.
The disadvantage is that interrupts can occur at any time – asynchronously – so you have to be careful when using them.