Properly cancel state switch tasks