How does the sleep function from the Thread class work?

    2 answers 2

    It simply informs the thread scheduler that the thread that called it does not need to be queued for planning the specified time.

    Sleep(0); It has a slightly different meaning - the flow tells the planner that it has worked, and it does not need its time slice.

    How it all works. The thread scheduler wakes up from time to time and stops the current thread. Then it selects a new thread and starts it (although it is more correct to say that it puts and removes from a pause if the thread was started earlier).

    • Only the scheduler does not stop the current thread, but reschedules a set of executable threads in accordance with scheduling criteria (there can be several actually executed threads). Do not forget that the OS takes into account all the threads in the system (and not just the threads of your program). - avp
    1. .sleep(3000) - pauses the flow for a specified time (3 seconds) in milliseconds

    2. .wait() - suspends until unblocking the notify() or notifyAll() methods

    • Pay attention to the label csharp - yozh
    • Yes, I saw, does it change the meaning of the methods? Besides their syntax? - Gorets
    • one
      Well, fast Google tells us that the wait / notify / notifyAll methods are generally in .NET in a different class and are called differently - so C # ers (by the way, do you call yourself that?) may not understand you. - yozh