CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Location
    Stuttgart, Germany
    Posts
    56

    Question Thread sleep with double

    Hello guys,

    I want to wait a certain time but it wont be always integer values, but decimals also.

    For example I want to wait half second and in my program it's used like 0.5.

    Do you have any solution to this?

    Best regards,
    Raul Bolanos.
    Last edited by raulbolanos; June 22nd, 2009 at 06:52 AM. Reason: [SOLVED]

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: Thread sleep with double

    The System.Threading.Thread.Sleep method's parameter is in milliseconds, so to wait for half a second do

    Code:
    System.Threading.Thread.Sleep(500);
    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    210

    Re: Thread sleep with double

    I would use the thread's sleep method. The parameter is ms and fine enough:
    http://msdn.microsoft.com/de-de/libr...1t(VS.80).aspx


    So in your case 0.5 seconds would be:
    Code:
    Thread.Sleep(500);

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

    Re: Thread sleep with double

    Just multiply your value times 1000.

    Code:
    float delay = 0.5;
    
    Threading.Sleep( delay x 1000 );
    Keep in mind that the Sleep( ) method is approximate and the system doesn't guarantee that your thread will be woken up at the precise moment the time expires.

    Btw, hopefully you are using Sleep( ) in a non-UI thread because otherwise you will hang the UI.

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