What's wrong with using Thread.Abort()

前端 未结 7 1977
执笔经年
执笔经年 2020-11-21 22:30

So I know that you shouldn\'t use

Thread.Abort()

But I\'ve never been given a good explanation. Is there a performance penalty or some hid

7条回答
  •  广开言路
    2020-11-21 22:52

    Because if you know that the thread is in some safe state in which it can be aborted, surely you can arrange better communication and have the thread exit cleanly.

    The thread could have taken a lock and be in the middle of changing some shared state, and the Thread.Abort will undo the lock and leave the shared state corrupted.

提交回复
热议问题