Reputation: 612
I have a thread which blocks itself on some lock.Now For some condition I want to kill the thread in c#. But the thing is that in thread.abort does not guarantees that it will kill the thread.
Upvotes: 0
Views: 268
Reputation: 2601
Assuming you want to kill the thread in a deterministic way when it encounters deadlock . Right ? Yes thread abort does not guarantee termination but it is almost always a bad idea to use Thread.Abort. If there was a way to kill the thread instantaneously it can lead to bigger problems . If this thread has taken lock on some resource , is in the middle of some uncommitted transaction etc ,and the thread holding these resource is abruptly killed no other thread can work on these resources. Best suggestion I can give is is to fix the deadlock issue rather than masking it.
Upvotes: 1
Reputation: 44931
If you really want a guarantee of thread death, your best option is to start a new process.
There is an excellent thread that discusses many of the possible pitfalls of thread.abort here.
Upvotes: 2