如何中止与ThreadPool.QueueUserWorkItem创建的线程 [英] How to abort threads created with ThreadPool.QueueUserWorkItem

查看:1566
本文介绍了如何中止与ThreadPool.QueueUserWorkItem创建的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法中止与QueueUserWorkItem创建的线程?

is there a way to abort threads created with QueueUserWorkItem?

或者,也许我不需要?如果主应用程序退出时会发生什么?是否所有线程创建的,它会自动中止?

Or maybe I don't need to? What happens if the main application exits? Are all thread created from it aborted automatically?

推荐答案

您不必放弃他们。当你的应用程序退出时,.NET会杀死任何的IsBackground线程= TRUE。在.NET线程池拥有的所有线程设置的IsBackground = true,所以你不必担心它。

You don't need to abort them. When your application exits, .NET will kill any threads with IsBackground = true. The .NET threadpool has all its threads set to IsBackground = true, so you don't have to worry about it.

现在,如果你正在创建由newing了线程Thread类,那么你要么需要放弃他们或设置它们的IsBackground属性设置为true。

Now if you're creating threads by newing up the Thread class, then you'll either need to abort them or set their IsBackground property to true.

这篇关于如何中止与ThreadPool.QueueUserWorkItem创建的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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