Change method of termination thread.

set a flag in dlg to teminate thread instead of using  TerminateThread
function.