I have been reading a lot about aborting threads and there seems to be something missing to do this easily on program exit. This is what I want to do but I will need some help.
I declared a global boolean called KillAllThreads (public static bool in abstact class).
I initialize it to false in my main program before my main window opens.
I then have some threads open and close. I keep count of opened and closed threads by using another global int called WorkingThreads. I increment WorkingThreasds as the thread starts and decrement is at the end of the thread. This has worked well so far for me.
When I exit the main window I switch the KillAllThreads to true
now comes the question:
How do I make the threads listen to the killAllThreads?
here is my idea in pseudo-code:
thread executes code while killallthreads is false.
as soon as killallthreads is true my code executes the thread abort line and decrements WorkingThreads.
when WorkingThreads == 0 I exit out program.