delay code

This is a discussion on delay code within the C# Programming forums, part of the General Programming Boards category; Hi, there. I'm working with an application that is kind of like a casino and I need help. I'm looking ...

  1. #1
    Registered User Grayson_Peddie's Avatar
    Join Date
    May 2002
    Posts
    96

    Question delay code

    Hi, there. I'm working with an application that is kind of like a casino and I need help. I'm looking for a code/command that can set the amount of delay before the execution of code. For example:

    Code:
    for(i = 0; i < 2; i++)
    {
        // Wait about 1 millisecond before the execution of code.
        // ...
        // Then execute a code.
    }
    So, how do I make a 1-ms delay? In this example, I had setup a for loop and it will be executed about 2 times to add a number to a stored number. For example, if I had it setup like this:

    Slot 1: 2
    Slot 2: 1
    Slot 3: 4

    Well, each slot will have a number up to a maxinum of 10. If it exceeds 10, then it will start from 0 in order to continue.

    If I had Slot1 set to be delayed about 4 milliseconds, Slot2 set to be delayed at 8 milliseconds, and Slot3 set to be delayed at 16 milliseconds, then I will get this:

    Slot 1: 6
    Slot 2: 9
    Slot 3: 9

    To give you a little more understanding of what I mean, here's how it works since after every millisecond, a number that was displayed in all the slots had been added:

    Slot 1: 2, 3, 4, 5, 6
    Slot 2: 1, 2, 3, 4, 5, 6, 7, 8, 9
    Slot 3: 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

    Well, I hope you get the understanding of what I mean. Plus, delay instruction can also be used for making smooth change to transparency, moving window, etc.

    So, does anybody know the code for delaying an execution of instruction/code/statement?

    Thanks in advance!
    -Grayson
    View in Braille.
    http://www.future-gpnet.com/braille.jpg

    Like a bolt out of the BLUE,
    Fate steps up and sees you THROUGH,
    When you wish upon a STAR
    YOUR DREAMS COME TRUE.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    Use the static method Sleep from System.Threading.Thread:

    int millisecond = 7;

    System.Threading.Thread.Sleep( millisecond );
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User Grayson_Peddie's Avatar
    Join Date
    May 2002
    Posts
    96
    Okay. Thanks!
    View in Braille.
    http://www.future-gpnet.com/braille.jpg

    Like a bolt out of the BLUE,
    Fate steps up and sees you THROUGH,
    When you wish upon a STAR
    YOUR DREAMS COME TRUE.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 11:38 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

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