My program uses two threads. One of them is created whenever I click an item in a listbox and does some processing before exiting.
I want to be able to end the second thread if it is already running when I click a different item in the listbox.
One thing I tried is having the second thread continue processing as long as some boolean value is true and then setting that value to false whenever the listbox selection changes. I would then use WaitForSingleObject() before re-creating the thread. This causes my program to hang most of the time.
What else can I do besides using TerminateThread()?