CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 1999
    Location
    Germany
    Posts
    2,338

    How long will Sleep sleep?

    Hello! I have a multithreaded application. I was wondering, if I do a Thread.Sleep(10*1000), will it do a sleep of 10 Seconds in "thread-time" or in "real-time"?

  2. #2
    Join Date
    May 2007
    Posts
    1,546

    Re: How long will Sleep sleep?

    I don't know what you mean by thread time, but that will sleep the thread for 10 seconds as measured by a clock on the wall.
    www.monotorrent.com For all your .NET bittorrent needs

    NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.

  3. #3
    Join Date
    Aug 1999
    Location
    Germany
    Posts
    2,338

    Re: How long will Sleep sleep?

    Thanks a lot!

  4. #4
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: How long will Sleep sleep?

    Thread.Sleep is capable of sleeping for approximately 3 1/2 weeks.

    it takes an int as it's parameter. the largest value of an int is 2^31 -1 which in this case is representative of milliseconds... you do the math.

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How long will Sleep sleep?

    Keep in mind that sleep is an approximate wait period.

    Since any threads with higher priority are scheduled before threads of lower priority, a lower priority thread may effectively continue to 'sleep' even after the sleep period has expired. This is because the scheduler will continue to run the higher priority threads until they've finished their work before scheduling the lower priority thread. If the sleep value in the lower priority thread has expired, then it will run (but this could be well after the intended sleep period).

    All that being said, generally there is little reason to use sleep.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured