Here is a wrapper around the Beep function in the kernel, taking a duration and a frequency. Nowadays Beep
uses the soundcard; in my days it used some piezo device glued on the motherboard.
using System;
using System.Runtime.InteropServices;
class BeepSample
{
[DllImport("kernel32.dll", SetLastError=true)]
static extern bool Beep(uint dwFreq, uint dwDuration);
static void Main()
{
Console.WriteLine("Testing PC speaker...");
for (uint i = 100; i <= 20000; i++)
{
Beep(i, 5);
}
Console.WriteLine("Testing complete.");
}
}
On my Win10 box I need to set the duration (last parameter) much larger then the 5 ms here, more up to 50 ms but to get something reasonable I have to make it 100 ms.
Or use the Console.Beep(Int32, Int32) method if you want to take the easy route. That method was introduced in .Net 2.0.