无法在c#中停止线程 [英] Not able to stop a thread in c#
问题描述
我有一个包含在后台运行的线程的应用程序。当我试图阻止 线程使用thread.Abort()它不会停止,它会继续执行并返回异常。
I have an application which contains a thread running in the background. When I try to stop the thread using thread.Abort() it does not stops, it continues execution and return exception.
你能建议任何更好的方法来停止一个线程以及如何使用thread.stop()。
Can you suggest any better way to stop a thread and how to use thread.stop().
提前致谢
推荐答案
您好,
用BackgroundWorker替换线程 - 它支持取消操作。
Replace Thread with BackgroundWorker - It support Cancel operation.
要终止线程,您需要退出线程功能。 Abort()没有踢你的函数 - 它会抛出一个异常,它会让你退出函数,但是...异常可以被取消。
To terminate the Thread you need to exit from thread function. Abort() didn't kick you of the function - it throw an exception which suppose to kick you out of the function, but... exception can be canceled.
这篇关于无法在c#中停止线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!