Jump to content
Fórum Script Brasil
  • 0

Threadabortexception - Problemas


Thiago Alencar
 Share

Question

Precisava realizar umas operacoes antes que meu thread fosse abortado.. de cara o threadAbortException parecia uma mao na roda.. porem percebi que nem sempre meu codigo dentro do bloco catch exception era executado ate o fim e o thread e' abortado antes disso. Talvez colocar este codigo dentro de um finally e seguir a seguinte ideia:

Aqui uma descricao sobre o mesmo:

"When a call is made to the Abort method to destroy a thread, the common language runtime throws a ThreadAbortException. ThreadAbortException is a special exception that can be caught, but it will automatically be raised again at the end of the catch block. When this exception is raised, the runtime executes all the finally blocks before ending the thread. Since the thread can do an unbounded computation in the finally blocks, or call Thread.ResetAbort to cancel the abort, there is no guarantee that the thread will ever end. If you want to wait until the aborted thread has ended, you can call the Thread.Join method. Join is a blocking call that does not return until the thread actually stops executing."

mas acho que li em algum lugar que nem sempre o codigo finally e' executado tambem.

Alguma ideia por que isto acontece?

abraco!

Edited by Thiago Alencar
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0
mas acho que li em algum lugar que nem sempre o codigo finally e' executado tambem.

desculpem acabei confundindo finally com finalize. O Finalize sim que não tem garantia de que sera executado, uma vez que e' usado pelo Garbage Collector do CLR - que e' imprevisivel.

parece que usando o finally funciona sim

Ate +

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.8k
    • Total Posts
      646.6k
×
×
  • Create New...