Click here to Skip to main content
15,867,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Is UI thread same as Background thread? My application is a console or windows service. I don't have a UI interface, so all processes are Background threads?

Also is UI thread a I/O bound or CPU bound?
Posted
Comments
[no name] 10-Oct-14 14:20pm    
What I mean to know is:

A process has a main thread.
Console: It serves the UI
WIN xyz: It serves the GUI
Service: It is simply the main thread.

I'm looking also forward for the answers.
Sergey Alexandrovich Kryukov 10-Oct-14 16:43pm    
This is not so. "Background thread" has a very special meaning in .NET. It takes some documentation reading. Please see my answer.
And OS accepted wrong answer, it happens... :-)
—SA
[no name] 10-Oct-14 17:07pm    
That's why I mentioned I'm looking for answers ;)
And no, OP seems to accpet the right answer (No. 2), but give me "un rato" to check it.
Saludos, Bruno
Sergey Alexandrovich Kryukov 10-Oct-14 17:50pm    
Thank you, Bruno. As to the OP, he has changed his mind under the pressure of evidence. :-) Right choice.
—SA
[no name] 10-Oct-14 17:58pm    
Not under pressure...some of us are learning here ;) and just learn ;)
Give us also a Little bit time for this.
Regards, Bruno

Main thread or UI thread is the thread that the OS calls into to start your program.

Background threads are things you start to do other stuff in parallel.

A thread can be IO bound or CPU bound depending on what it is doing.
 
Share this answer
 
Comments
[no name] 10-Oct-14 15:13pm    
@Mehdi, what is meant by the term "UI"? I thought it was "User Interface". Does "User Interface" means "GUI"? But I don't have a GUI because of console application unless WPF or Windows Form application.
Mehdi Gholam 10-Oct-14 15:23pm    
Think of it as where main() is.
Sergey Alexandrovich Kryukov 10-Oct-14 16:45pm    
No, sorry, you are mistaken, just because you did not read about it: "background thread" has a very special meaning in .NET. It takes some documentation reading.
Also, you explanation of UI thread is inaccurate (strictly speaking, incorrect), but the difference is very delicate.

Please see my answer.

Look, I did not down-voted you answer, because the issues are very delicate, but I really suggest you to remove your answer, to avoid confusing the readers.

—SA
I would define UI thread is the thread where Application.Run is called. This is different from the definition of Solution 1, which is almost correct.

I can explain the difference. It is possible to have two (or more) different threads, and run different UI on different thread. Those UI will execute in different threads and unrelated to each other. Communication between those thread would require Invoke or BeginInvoke (the method of System.Windows.Forms.Control or Dispatcher). This scenario is really exotic and rarely used (for those who may not believe me: yes, I tried it! you can try it, too). Usually, the UI thread is the same thread as the thread initially created, where the entry-point is executed. So, typically, the UI thread is the same as entry-point thread. But this is not the law, you could make those threads different.

Strictly speaking, there is no the "official" term for "UI thread". I just pointed out that the entry-point thread and UI thread can be different. (By the way, in WPF, two threads are working for UI. Things are a bit more complex than many think.)

Now, how about all other threads. No, they don't have to be "background threads" (so the Solution 1 is totally incorrect here), they are just some extra threads. Why? Because this term has a very specific meaning in .NET: this is the thread with the property System.Threading.Thread.IsBackground assigned to true. What is does? Background thread don't hold the process when the main thread is terminated, as the "usual" thread does. Please see:
http://msdn.microsoft.com/en-us/library/system.threading.thread.isbackground%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 
v4
Comments
[no name] 10-Oct-14 17:16pm    
My 5...but a question: is it not _very_ theoreticaly? Is it not that 99.8% the main thread is the one who serves UI/GUI?
Sergey Alexandrovich Kryukov 10-Oct-14 17:48pm    
Thank you Bruno.
This is not theoretical or practical, this is just truth, whatever it is. I said in the first place that the situation when a UI thread is different from the entry-point thread are very rare. So what? You probably understand that if the statement has infinite number of confirming example and only one counter-example is still false. It's better to afraid of telling lie than afraid of being too boring... :-)
—SA
[no name] 10-Oct-14 18:22pm    
Sergey Alexandrovich Kryukov 10-Oct-14 18:25pm    
The top answer is correct, but:
1) This is exactly what I already told you and what you could read from the MSDN (original source of information!) article I referenced;
2) You asked two questions, not just this one. I answered both.
—SA
Mehdi Gholam 10-Oct-14 19:46pm    
5'ed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900