Learning never exhausts the mind


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);


Sharing is caring!

If you enjoyed this post, please share it with others. Click one of the social media buttons below to share on Facebook, Twitter, LinkedIn, Pinterest or email to a friend.

2 thoughts on “Beeping the PC Speaker in C#
  • 23rd November 2009 at 12:00 am

    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?

    • Tim Trott
      10th December 2009 at 12:00 am

      Try adding

      using System.Runtime.InteropServices;


Leave a Reply

Fields marked with * are mandatory.

We respect your privacy, and will not make your email public. Hashed email address may be checked against Gravatar service to retrieve avatars. This site uses Akismet to reduce spam. Learn how your comment data is processed.