I have a local thread that is started on button-click event from the main thread. Its name is RegistrationThread. I want to stop this thread on another stop button-click event.
How do I stop RegistrationThread that is a local thread and I cannot access this thread by its name?
If I get the RegistrationThread, then is it possible to suspend it? How to do this?
Aborting a thread is usually a measure of last resort. The reason is because it can cause a lot of unintended side-effects. The best practice is to allow the worker thread to end gracefully at predetermined safe points. This can be done correctly in many different ways. One of the simplest is to set a flag indicating to the worker thread that it should begin shutting down.
If you really want to abort a thread then you could always save away a reference to the
Threadand then callAborton it from your stop button click event.