By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,510 Members | 1,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,510 IT Pros & Developers. It's quick & easy.

C# ...1 beep 1 second silence

P: 19
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???
Feb 19 '09 #1
Share this Question
Share on Google+
3 Replies


Plater
Expert 5K+
P: 7,872
Try using Thread.Sleep()
Feb 19 '09 #2

tlhintoq
Expert 2.5K+
P: 3,525
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.
Feb 19 '09 #3

vekipeki
Expert 100+
P: 229
@tlhintoq
I wouldn't say too much, since there is a sample in MSDN for Console.Beep that does the same thing:

http://msdn.microsoft.com/en-us/library/4fe3hdb1.aspx
Feb 20 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.