Insert thread into foreach