Close threads when exiting

The application thread was still running when the app exits, added lines
to close the open threads on the exit button click event.