C#Threads.Abort() [英] C# Threads.Abort()

查看:153
本文介绍了C#Threads.Abort()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果一个线程运行的函数 FUNC1 调用另一个函数 FUNC2 里面...

If a thread is running a function func1 that calls another function func2 inside it...

然后我打电话Thread.Abort的()

Then I called thread.Abort()

请问这站 FUNC1

FUNC1 FUNC2 和所有的功能 FUNC1 呼吁??

Will this stop func1 only
OR func1 and func2 and all the functions func1 has called??

感谢

编辑:这里有更多的细节:

FUNC1 被称为新线程,它不断呼吁 FUNC2 上定期...

FUNC2 开始做一些如果某些数组不为null只有工作..它完成并返回

func1 is called in a new thread, it continuously calls func2 on regular basis...
func2 begin doing some work only if some array is not null.. it finishes it and return

当主管想要保存数据,它将中止 FUNC1 - 进而使得阵列空,节省了数据,然后用新的数组中填写..和 FUNC1 ..

When supervisor wants to save data, it aborts Thread of func1- and then makes array null, saves data, then fill in the array with new one.. and starts Thread with func1 again..

有时引发异常,因为数组是空的 FUNC2 ..所以FUNC1终止并不影响FUNC2

Sometimes exception is raised because array is null in func2.. so func1 abort did not affect func2

推荐答案

Thread.Abort的 不保证停止线程,你应该尽量避免使用它。

Thread.Abort is not guaranteed to stop the thread and you should avoid using it if possible.

调用此方法的一般终止线程。

Calling this method usually terminates the thread.

重点煤矿。

它的作用是提高一个 ThreadAbortException 目标线程。如果你发现此异常,代码将继续执行,直到到达catch块,此时异常会自动重新抛出的结束。如果你不抓住它,它类似于一个正常的例外 - 它传播到调用堆栈

What it does is raise a ThreadAbortException in the target thread. If you catch this exception, the code will continue executing until it reaches the end of the catch block, at which point the exception is automatically rethrown. If you don't catch it, it is similar to a normal exception - it propagates up the call stack.

假设你没有捕获异常,所有的代码在该线程运行将停止运行。从该线程将不受影响启动的其他线程。

Assuming you don't catch the exception, all the code running in that thread will stop running. Other threads that were started from that thread will not be affected.

这篇关于C#Threads.Abort()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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