What is a worker thread and its difference from a thread which I create?

后端 未结 3 1189
野性不改
野性不改 2021-01-31 08:35

I create a thread by

Thread newThread= new Thread(DoSomeWork);

.
.
.
private void DoSomeWork()
{
}

Is this any different from a Worker thread?

3条回答
  •  粉色の甜心
    2021-01-31 09:29

    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 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.

    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.

提交回复
热议问题