Destroying threads

The Thread.Abort method is used to stop a thread. Once aborted, it cannot be restarted. However, when you invoke Thread.Abort, it doesn't terminate the thread immediately since the Thread.Abort statement throws a ThreadAbortException, which needs to be caught. Then, the cleanup code should be executed. If you call the Thread.Join method, this will make sure the thread waits until the other thread's execution is completed. The join method depends on the timeout interval, so if it's not specified, then the wait is not guaranteed.

When your own code aborts a thread and you don't want to rethrow it, use the ResetAbort method. You will learn more about how to rethrow exceptions in Chapter 7, Implementing Exception Handling.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.253.223