[C#] Threading

Yadz

Active Member
Feb 20, 2015
174
25
So I'm new to C# and were wondering: Whats the best way to keep a thread alive in C#? For example if I want to constantly check if a car got less than 0 litres fuel (bad example), how should I do it in a thread? The only way I can think of is using is a while(true) loop with an if statement in it (in this case).
Also could the while(true) loop affect the application in a bad way? What if I got a while(true) loop in a thread with 50 if statements in it? Is it bad to do that?
 

Jaden

not so active
Aug 24, 2014
886
263
Because he needs help? Thought you were a C# coding master, why not help him instead of asking obvious questions
First, I needed to know why he was planning on creating a thread instead of using a background worker, which could've been for multiple reasons like the fact that his server is running slow with everything in the background, and the task he needs to accomplish needs to be fast and somewhat "real-time".

And how does "Because he needs help" answer the question "Why do you need to create a thread for this?"

Are you stupid? The answer to that "obvious question" would determine the way to go with what hes trying to do. I'm not going to advise him on creating a new thread when he can just simply run his loop in the background. And who said I was a "C# coding master", idiot.
 
Last edited:

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,398
962
First, I needed to know why he was planning on creating a thread instead of using a background worker, which could've been for multiple reasons like the fact that his server is running slow with everything in the background, in the task he needs to accomplish needs to be fast and somewhat "real-time".

And how does "Because he needs help" answer the question "Why do you need to create a thread for this?"

Are you stupid? I'm not going to advise him on creating a new thread when he can just simply run his loop in the background. And who said I was a "C# coding master", idiot.
That is not a good reason to use a BackgroundWorker whatsoever. Not to mention a BackgroundWorker is just its own, dedicated thread. The whole purpose of BackgroundWorker is for time consuming operations, so you're way off your mark on "the task he needs to accomplish needs to be fast and somewhat real-time".

My initial reply was an obvious jest at the multiple uses of the definition of thread, from a programming standpoint and as a forum topic.

It's pretty obvious that this is for a some school work and not the Habbo faggotry you engage in relentlessly. And you've boasted about your C# (and various other programming language) prowess numerous times on the shoutbox. Your reply is a clear indication that this is simply not true.
 

Jaden

not so active
Aug 24, 2014
886
263
That is not a good reason to use a BackgroundWorker whatsoever. Not to mention a BackgroundWorker is just its own, dedicated thread. The whole purpose of BackgroundWorker is for time consuming operations, so you're way off your mark on "the task he needs to accomplish needs to be fast and somewhat real-time".

My initial reply was an obvious jest at the multiple uses of the definition of thread, from a programming standpoint and as a forum topic.

It's pretty obvious that this is for a some school work and not the Habbo faggotry you engage in relentlessly. And you've boasted about your C# (and various other programming language) prowess numerous times on the shoutbox. Your reply is a clear indication that this is simply not true.
Can you read? I said that would be a reason to use a thread instead of a background worker? And a background worker is not its own dedicated thread, but something that is executed along with the main thread, so the only time it would be "time consuming" is if the main thread had a shitload of code to be executed.

And since when did anyone mention anything about Habbo?
 

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,398
962
Can you read? I said that would be a reason to use a thread instead of a background worker? And a background worker is not its own dedicated thread, but something that is executed along with the main thread.

And since when did anyone mention anything about Habbo?

The BackgroundWorker class allows you to run an operation on a separate, dedicated thread

You clearly know nothing.
 

Jaden

not so active
Aug 24, 2014
886
263



You clearly know nothing.
Since when did I literally mean the "BackgroundWorker" class? Here we go again, "background" meaning it runs in the background with the main thread, "worker" meaning the task to be accomplished. I don't know how I can be more thorough with you, you are incompetent and know nothing about C#, so stop trying to quote google.

What I was talking about:


You are stupid, regardless of the fact that I wasn't talking about "BackgroundWorker":
 

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,398
962
Since when did I literally mean the "BackgroundWorker" class? Here we go again, "background" meaning it runs in the background with the main thread, "worker" meaning the task to be accomplished. I don't know how I can be more thorough with you, you are incompetent and know nothing about C#, so trying to quote google.

What I was talking about:


You are stupid, regardless of the fact that I wasn't talking about "BackgroundWorker":
Keep backpedaling. You mention background worker in regards to C# and for some reason think it's not reasonable to consider that means the BackgroundWorker class (which is what any person who knows C# would think).

Your second link is useless. This one will clearly explain why you know nothing:


And saying I'm incompetent is laughable. I got my MCSA and MCSE well before you hit puberty. Despite working with Unix for 15+ years, I can guarantee that I know much more about the Windows OS than you.
 

Jaden

not so active
Aug 24, 2014
886
263
Keep backpedaling. You mention background worker in regards to C# and for some reason think it's not reasonable to consider that means the BackgroundWorker class (which is what any person who knows C# would think).

Your second link is useless. This one will clearly explain why you know nothing:


And saying I'm incompetent is laughable. I got my MCSA and MCSE well before you hit puberty. Despite working with Unix for 15+ years, I can guarantee that I know much more about the Windows OS than you.
Any person who knew C# would think of a timer that executed in the background, in reference to this forum thread. Realize that a space between "background" and "worker" goes along way when we're on about C#.

And if you want to make this about who knows more (because you're clearly intimidated), I can assure you, you don't.
 

Yadz

Active Member
Feb 20, 2015
174
25
Why would you need to create a thread for this?
That did not really answer my question, anyways, it was just an example, couldn't think of anything else. Also, I didn't know about background workers (timers), currently reading about it. However, now I wonder what threads are even used for and when should I use a thread?

Thanks in advance.
 

Adil

DevBest CEO
May 28, 2011
1,278
716
That did not really answer my question, anyways, it was just an example, couldn't think of anything else. Also, I didn't know about background workers (timers), currently reading about it. However, now I wonder what threads are even used for and when should I use a thread?

Thanks in advance.
Threads allow you to do more than one thing at once. Usually, threading is used in a situation where you handling many things at once, e.g. a graphical user interface updating some data on a server.
 

Users who are viewing this thread

Top