Correctly shutdown the thread when the application end.

NOTE: this still do not handle the shutdown while the thread is working, in that case the win close but the thread must finish his work before exiting