什么是工作线程及其与我创建的线程的区别? [英] What is a worker thread and its difference from a thread which I create?

查看:145
本文介绍了什么是工作线程及其与我创建的线程的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过创建一个线程

Thread newThread= new Thread(DoSomeWork);

.
.
.
private void DoSomeWork()
{
}

这与Worker线程有什么不同吗?如果它是..哪个更好,何时应使用工作线程? 我的应用程序需要有很多线程来进行监视,刷新..

Is this any different from a Worker thread? If its is..which is better and when should I use a worker thread? My application needs to have lots of thread doing monitoring, refreshing..

推荐答案

通常,术语工作线程用于描述正在执行当前线程的线程中的另一个线程-在许多情况下,它是前台线程或前台线程. UI线程.但是,这并不是一成不变的.

Generally the term worker thread is used to describe another thread from the one that is doing the work on the current thread - which in lots of cases is a foreground or UI thread. This is not cast in stone however.

Windows程序通常使用单个 primary 线程来管理UI,并且这通常是同步的(即,一个接一个地运行).如果要执行的任务很长,那么要避免在此类程序中使UI块成为问题,您可以使用工作线程(可以是前台线程或后台线程)来进行工作(与主线程异步) ,然后将结果显示回主线程以供使用.

Windows programs generally use a single primary thread to manage the UI and this is generally synchronous (i.e. things runs one after the other). If there is a long running task to perform then to avoid making the UI block in these kinds of programs you use a worker thread (which can be either a foreground thread or a background thread) to do the work (asynchronously to the primary thread), and then present the results back to the primary thread to consume.

在Windows程序中,这是通过消息完成的.如果使用诸如.net框架之类的特定库,则可以使用诸如ThreadPool和BackgroundWorker之类的特殊实用程序类来简化后台或工作线程的处理.但是像往常一样,您可以使用平台原语来达到相同的目的.

In windows programs this is done via messages. If you use particular libraries such as say the .net framework, then special utility classes such as ThreadPool and BackgroundWorker are available to make background or worker thread handling easier. But as always you can using the platform primitives to achieve the same end.

这篇关于什么是工作线程及其与我创建的线程的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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