Web Design that taps into the haromny and vision of your dreams.

Beeping the PC Speaker in C#

By on in Coding

25 words, estimated reading time 1 minutes.

This short snippet uses a system call to sound the PC speaker at a given frequency and duration.

public static extern bool Beep(UInt32 frequency, UInt32 duration);
public static void BeepMe()
  int Frequency = 500;
  int DurationInMS = 100;
  Beep(Frequency, DurationInMS);

Last updated on: Thursday 22nd June 2017



Have a question or suggestion? Please leave a comment to start the discussion.



Error 1 The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?) C:Documents and Settings[Anonymous]My DocumentsVisual Studio 2008Projects[Private Project][Private Project]Form1.cs 68 10 [Private Project]

What to do?

Reply to Anonymous
Tim Trott

Tim Trott

Try adding

using System.Runtime.InteropServices;

Reply to Tim Trott


Leave a Reply

Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Your email address will not be published.