Beep Sound in C#.NET Framework

This gets asked all the time on our internal alias, so I am sure google gets asked a lot, here is my effort to provide an answer. 


No, the .NET Framework V1.0\V1.1 does not support Beep()… In those platforms you can

(a)     PInvoke to Win32:

public static extern bool Beep(int freq,int duration);


(b)     See MessageBeepType


(c)     Use the Beep sound in the VB assembly
Add a reference to the Microsoft.VisualBasic.dll assembly and use




Of course in Whidbey (.NET Framework V2.0) we support Beep() directly in the Framework:

Via Console.Beep() and Console.Beep(int frequency, in duration).


Update (11/22/05):

For the .NET Compact Framework I'd suggest you use:

namespace CFBeep
    public partial class Form1 : Form
        public static extern int PlaySound(
            string szSound,
            IntPtr hModule,
            int flags);

        public Form1()

        private void button1_Click(object sender, EventArgs e)
            PlaySound(@"\Windows\Voicbeep", IntPtr.Zero, (int)(PlaySoundFlags.SND_FILENAME | PlaySoundFlags.SND_SYNC));


    public enum PlaySoundFlags : int
        SND_SYNC = 0x0,     // play synchronously (default)
        SND_ASYNC = 0x1,    // play asynchronously
        SND_NODEFAULT = 0x2,    // silence (!default) if sound not found
        SND_MEMORY = 0x4,       // pszSound points to a memory file
        SND_LOOP = 0x8,     // loop the sound until next sndPlaySound
        SND_NOSTOP = 0x10,      // don't stop any currently playing sound
        SND_NOWAIT = 0x2000,    // don't wait if the driver is busy
        SND_ALIAS = 0x10000,    // name is a registry alias
        SND_ALIAS_ID = 0x110000,// alias is a predefined ID
        SND_FILENAME = 0x20000, // name is file name
        SND_RESOURCE = 0x40004, // name is resource name or atom



Comments (13)

  1. Eric says:

    What about having a real Sound API to play wavefiles in the Framework (e.g. simple sound buffers, play samples, etc). Something like System.Sound.dll.

    It keeps me stunned me for a while that MS never gets their act together on this.

    I don’t want a dependency on DirectX APIs to play a song. The new stuff in Longhorn looks really overdesigned (and is Longhorn only so no one can use it).

    In the end we end up doing stuff in Flash (which has crappy Sound support as well).

    Why is it so hard to do a System.Sound API in the Framework?

  2. KevinT says:

    Echo Eric. 🙂

  3. Sagal says: this guy was part of the tracker scene, he is doing nice .NET APIs and he works at Microsoft. I wonder what he is working on.

  4. Sagal says:

    Beep is fun.

  5. Brad Abrams says:

    Fair point, Windows Forms is adding a PlaySound API for WHidbey (.NET Framework 2.0)… I should have listed that as well….

  6. J. Daniel Smith says:

    Does the new PlaySound() API support WMA (and MP3) files or just WAV?

    I would hope Microsoft would support its own WMA format (better), but I suspect this is a wrapper around a Win32 API and that only WAV is supported.

  7. Rene says:

    Brad, wrapping PlaySound() is not enough. You will need WAV, WMA and MP3 support. Also you need sound buffers (to mix your own samples on the fly). This is NOT Windows Forms functionality, it should work compeltly independent of Windows Forms.

  8. Brad, try the following:



Skip to main content