Using Thread.Sleep Correctly RRS feed

  • Question

  • So this link was posted in another thread:


    Saying that Thread.Sleep should NEVER be used (other than Thread.Sleep(0), but I don't use that). So here's what I'm using it for, please tell me if there's a better way. I have a thread polling hardware for data (reading a size register and then reading data if the size > 0). Most of the time the size is 0, and I have other threads also polling for data. So I put a Thread.Sleep in after every check. Is this bad? Is there a better way to do this?
    Tuesday, July 7, 2009 2:28 PM


  • Are you using the Sleep to let the other threads have a go? If so, you don't really need to do that, since the OS will do that for you. But if you are using the Sleep to prevent your thread from over-querying the hardware, perhaps what you need is a timer.
    • Marked as answer by Figo Fei Friday, July 10, 2009 7:51 AM
    Tuesday, July 7, 2009 2:34 PM