C# ...1 beep 1 second silence

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alireza6485
    New Member
    • Jan 2009
    • 19

    C# ...1 beep 1 second silence

    I need to write a C# program that asks for a pattern and for each pattern beeps one and goes silence for 1 second.
    This is my code:
    for (int i=0;i< pattern; i++)
    {
    Console.Beep();
    *************** ** //I have no idea what to put for 1 sec of silence


    }

    any suggestions???
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Try using Thread.Sleep()

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      More class homework??

      Be honest... This is a programming class homework assignment, right?
      I'm going to guess the next step to the ambulance siren assignment

      Posting guidelines about homework

      How much looking around the internet have you done on this? How many different methods have you tried, before asking for help? Have you tried a google search for 'time delay' or 'wait loop' or 'time check' or 'time compare' etc.?

      By the way a for loop counting the way you have won't get you 1 second of beeping. It will get you beeping for however long it takes that particular PC to count to your supplied number ("pattern"). A 1 GHz computer will beep 3 times longer than a 3 GHz computer, since it will take longer for it to count to the same maximum number.

      You might want to look at DateTime objects. This way you can check the DateTime before you go into the loop, keep checking it while in the loop, and then break out of the loop when the current time is greater than the start time plus 1 second.

      TIP: If you read the above paragraph like a word problem, it heavily hints at the code you would write to do it.

      Comment

      • vekipeki
        Recognized Expert New Member
        • Nov 2007
        • 229

        #4
        Originally posted by tlhintoq
        How much looking around the internet have you done on this?
        I wouldn't say too much, since there is a sample in MSDN for Console.Beep that does the same thing:

        Comment

        Working...