add a ThreadFunction class and use it