I’m relatively new to coding; most of my “work” has been just simple GUI apps that only function for one thing, so I haven’t had to thread much.
Anyway, one thing I’m wondering about threading is if you want to keep a thread alive forever to do whatever job it’s doing (processing, waiting for input, whatever), is it normal to format it like so:
while (true) {
// do stuff
Thread.Sleep(1000);
}
(or something along those lines)…? Or is this not safe and should it be avoided if possible?
Yep, that’s what you do.
But typically it’s like:
Because sometimes you may like to have someone/something else to have the ability to stop you.