[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Play tones with specific frequencies in C#

[Play tones with specific frequencies in C#]

This example shows how you can play tones with a given frequency and duration. When the user clicks the Play button, the following code plays a tone.

private void btnPlay_Click(object sender, EventArgs e) { int freq = int.Parse(txtFrequency.Text); int duration = int.Parse(txtDuration.Text); System.Console.Beep(freq, duration); }

The code parses the tone's frequency (Hz) and duration (ms) from text boxes. It then calls System.Console.Beep to play the tone for the indicated duration.

Note that System.Console.Beep is synchronous so it waits the specified duration before returning. That means you can't use this method to play a tone while the program does other things and you can't use this method to play multiple tones at the same time.

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.