Checking the state before scheduling a new task