patch to quit thread when close window