I dont know why your program becomes slow. You should be using the thread with just one statement of FindWindow or FindWindowEx API.