sleep()

This is a discussion on sleep() within the C# Programming forums, part of the General Programming Boards category; I use this code inside a buttoncontrol. I wonder if it is possible after the first if-statement to "Pause" for ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    383

    sleep()

    I use this code inside a buttoncontrol. I wonder if it is possible after the first if-statement to "Pause" for 1 second before it continues with the second if-statement.
    I have heard something about sleep(n) where n stands for milliseconds.
    But the compiler doesn´t recognice this syntax.

    Code:
    int i = 5;
    
    if( i > 0 )
    {
        i = 2;
    }
    
        sleep(100) //This does not work
    
        if( i == 2 )
        {
            i = 0;
        }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    In Windows, there is a "Sleep()" function - not sure if it's called something else in C# tho'.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    383
    I am not sure where to post this question but I use VC++.
    I have tested to write both Sleep(100) and sleep(100).

    I tried to #include <windows.h> but it seems that this header wasn&#180;t found.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Coding View Post
    I am not sure where to post this question but I use VC++.
    I have tested to write both Sleep(100) and sleep(100).

    I tried to #include <windows.h> but it seems that this header wasn´t found.
    Perhaps this is what you want: http://msdn.microsoft.com/en-us/libr...ep(VS.71).aspx

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    383
    Yes, thank you...

    I tried Thread::Sleep(1000) and it worked fine.

  6. #6
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    This is a C# board....assuming you are coding in C# then of course the statement #include <windows.h> will not work.
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [pthread] cancellable sleep in win32?
    By cyberfish in forum C++ Programming
    Replies: 2
    Last Post: 08-11-2007, 03:30 AM
  2. Sleep works with just one thread, but not 2
    By finkus in forum C++ Programming
    Replies: 5
    Last Post: 12-01-2005, 09:17 PM
  3. Problem with Sleep() #$@^#$%^
    By intruder in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2004, 07:46 AM
  4. why do we require sleep?
    By jinx in forum A Brief History of Cprogramming.com
    Replies: 43
    Last Post: 07-14-2004, 09:21 AM
  5. Sleep is overrated...
    By Polymorphic OOP in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 01-24-2003, 12:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21