-
Threading Question
I have a bunch of created threads... no problems with any of that. No problems at all actually, I just have a question.
My question is, how would i go about aborting all threads dead in their tracks. I assume I would be using a For Each / Next loop, however I'm not sure of the actual pointers I'd be using for that loop. I've tried to go through the intellisense but have come up with nothing. I've read on google that using .Abort is a bad idea as well so before I take that route I was wondering if anyone could shed some light. I don't want the threads to finish doing whatever they were doing. I just want everything to stop with the click of a button. Is this possible?
-
Re: Threading Question
Calling Thread.Abort is the way to stop a thread dead in its tracks. The reason it can be a bad idea is that you might leave your application or some resource in an invalid state if you abort a thread when it's halfway through a task. It's generally better to set a flag somewhere and have the thread test that flag intermittently at safe points. It can then exit gracefully after performing the appropriate cleanup. If you do decide to go the Abort route then you will need to handle the ThreadAbortException that will be thrown, at which point you can perform some cleanup if required.