Adding multithreading to check if the Agent needs to switch off