What is the main difference between Thread.Abort and Thread.Finish?

Asked

Viewed 65 times

0

I started working with threads recently and came across the need to close a thread, eliminate it altogether. After some researches I discovered the methods Abort and Finalize, however I did not understand what the main difference between both, and which factors determine which of these use.

Thanks in advance.

  • 1

    Note that Finalize is not a public method.

1 answer

1


Thread.Abort:

Generates a Threadabortexception in the thread in which it is invoked, to start thread shutdown process. Generally, the call to this method terminates the thread.

That is, the Thread. interrupts the thread process at any time, asynchronously, at any point in the application. However, it is not a good practice to use the method, usually only in the process of terminating the program, because it ends up leaving processes in ends up leaving open processes.

Thread.Finalize

Ensures that resources are released and other cleaning operations are performed when the garbage collector recovers the Thread object.

Method that the Garbage Collector calls when the object is ready to be finished.

That is, the difference is that Abort interrupts the Thread at the exact moment of execution, and can leave resources open, while Finalize waits for Garbage Collector to understand that the object is being finalized, being relatively safer, but there are still reservations.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.