你不能,该方法使用内核的功能。我将证明:
[SecuritySafeCritical]
[HostProtection(SecurityAction.LinkDemand, UI = true)]
public static void Beep(int frequency, int duration)
{
if (frequency < 37 || frequency > 32767)
{
throw new ArgumentOutOfRangeException("frequency", frequency, Environment.GetResourceString("ArgumentOutOfRange_BeepFrequency", new object[]
{
37,
32767
}));
}
if (duration <= 0)
{
throw new ArgumentOutOfRangeException("duration", duration, Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
}
Win32Native.Beep(frequency, duration);
}
这是Console.Beep
的代码,它使用Win32Native.Beep
实际(从它上面的检查除了)执行的蜂鸣声,并且该方法导致:
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool Beep(int frequency, int duration);
的函数从内核导入。
除非你硬编码和修改你的内核,否则你不能。 (我确信你不想)
我可以给你一个替代方案:http://naudio.codeplex.com/,你可以用这个工具控制你的声音,并给它流。 (您可以创建不使用文件作为源的流)
'Console.Beep'不是C#的一部分# – 2014-11-01 19:58:28
@JohnSaunders - 没有意识到。感谢编辑 – ArtOfCode 2014-11-01 19:58:49
C#编程语言和.NET Framework是两个不同的东西。 – 2014-11-01 20:00:17