Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6689325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:30:22+00:00 2026-05-26T05:30:22+00:00

While commenting on an answer in this other SO post , the point came

  • 0

While commenting on an answer in this other SO post, the point came up that use of the Thread.Sleep() method is a code smell.

I have a hard time believing there is no use of this method that doesn’t indicate that you’re doing something wrong. I can think of a couple off the top of my head:

  • Programmatically closing other applications; unless you want to kill the app (sometimes even then) you need to wait a few seconds for it to terminate gracefully.
  • .NET 2.0 code: yes, it still exists. Thread.Yield() wasn’t invented until .NET 4, so if you want to let other applications do their thing while you’re stuck in some polling loop, a Thread.Sleep() for a short interval is the way to do it.

So, why would Thread.Sleep be such a terrible line of code to use in any circumstance that it would smell so?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:30:23+00:00Added an answer on May 26, 2026 at 5:30 am

    I think you misunderstand what a code smell is. A code smell is something that is frequently misused or that tends to suggest a poor design. It means you should investigate it, not that you should avoid it!

    Thread.Sleep often indicates that a thread is waiting for something but has no way to know how long it should wait. That usually indicates that a control function that should be closed loop is instead implemented as an open loop.

    It is also sometimes used as a broken way to increase fairness. But fairness is generally bad because it has costs (extra context switches at a minimum) and it’s not like your threads will file union grievances. There is generally no reason to be fair to them since they’re all cooperating to get work done.

    Of course if it’s the best way to get a job done, or the good enough in a case where other solutions would require more effort or entail higher risk, you should use it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After some stupid musings about Klingon languages, that came from this post I began
While maintaining an old product, I came across an error that results in the
All, I've run it down to this point by commenting, breakpoints, etc. The program
UPDATED: I've updated the code based on the correct answer below. This works but
I'm having this inconvenience while commenting. But I was wondering how you guys would
While commenting on new features in ghci I wished that ghci had the ability
While creating a file synchronization program in C# I tried to make a method
So I have two works computer, one that I use mainly for development, the
I have to use hardcoded values for certain fields because at this moment we
Unfortunately, the answer to this question isn't quite as simple as it sounds... but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.