Is it possible to kill the BackgroundWorker's thread?

后端 未结 2 2026
小鲜肉
小鲜肉 2021-01-18 09:20

Is it possible \"kill\" the thread of a BackgroundWorker?

In my DoWork event, I can\'t check the cancellation flag, because I have a blocki

2条回答
  •  悲&欢浪女
    2021-01-18 09:42

    No, you can't kill the BackgroundWorker thread, you can only try to cancel it as you noticed, but it requires some interaction from the background thread itself to stop the work: "The worker code should periodically check the CancellationPending property to see if it has been set to true." (c) MSDN

    If you need full control over a thread, you will have to create it by yourself using Thread class.

提交回复
热议问题