Threads: Added a check for cancelled tasks.