C#线程 - 中断 [英] C# Threads - Interruption

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

问题描述

通常情况下,我们将中断一个线程这是在WaitSleepJoin状态或运行状态?

Normally will we interrupt a thread which is in "WaitSleepJoin" state or "Running" state?

推荐答案

通常你不'T中断一个线程在所有...但如果你尝试,它实际上不会直到下次块中断。从 MSDN

Normally you don't interrupt a thread at all... but if you try to, it won't actually be interrupted until it next blocks. From MSDN:

如果此线程当前未
挡在等待,睡眠,或加入
状态时,它就会被打断时,
下一开始阻塞。

If this thread is not currently blocked in a wait, sleep, or join state, it will be interrupted when it next begins to block.

ThreadInterruptedException被抛出
在中断线程,而不是
,直到线程块。如果线程
从未块,该异常被从未
抛出,因此线程可能
完整而没有被
中断。

ThreadInterruptedException is thrown in the interrupted thread, but not until the thread blocks. If the thread never blocks, the exception is never thrown, and thus the thread might complete without ever being interrupted.

这篇关于C#线程 - 中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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