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

Beeping the PC Speaker in C#

C# Beeping Speakers

Written By on in C#

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




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

Your email address will not be published.

If you find something abusive or that does not comply with our terms or guidelines please flag it as inappropriate.

Copyright © 2001-2018 Tim Trott, all rights reserved. Web Design by Azulia Designs

This web page is licensed for your personal, private, non-commercial use only.

Disclaimer, Privacy & LegalSitemapContact Me