无法在c#中停止线程 [英] Not able to stop a thread in c#

查看:234
本文介绍了无法在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆