visual-studio Visual Studio:如何在遇到断点时触发警报?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/80564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio: How to trigger an alarm when a breakpoint is hit?
提问by Ashwin Nanjappa
Is there a way to trigger a beep/alarm/sound when my breakpoint is hit? I'm using Visual Studio 2005/2008.
当我的断点被击中时,有没有办法触发蜂鸣声/警报/声音?我使用的是 Visual Studio 2005/2008。
回答by Nescio
Windows XP
视窗 XP
Control Panel -> Sounds and Audio... -> Program Events - Microsoft Developer -> Breakpoint Hit
控制面板 -> 声音和音频... -> 程序事件 - Microsoft Developer -> Breakpoint Hit
Windows 7
Windows 7的
Control Panel -> All Control Panel Items -> Sounds -> Sounds (tab) - Microsoft Visual Studio -> Breakpoint Hit
控制面板 -> 所有控制面板项目 -> 声音 -> 声音(选项卡) - Microsoft Visual Studio -> 断点命中
回答by Andrew Backer
Yes, you can do it with a Macro assigned to a breakpoint. This works in VS 2005, I assume 2008 will work as well. I assume you don't want a sound on EVERY breakpoint, or the other answer will work fine. There is probably a way to play a specific sound, but I didn't dig that hard. Here are the basic steps:
是的,您可以使用分配给断点的宏来实现。这适用于 VS 2005,我认为 2008 也适用。我假设您不希望在每个断点上都有声音,否则其他答案将正常工作。可能有一种方法可以播放特定的声音,但我并没有那么努力。以下是基本步骤:
Add A New Macro Module(steps below the code)
添加新的宏模块(代码下方的步骤)
Imports System.Runtime.InteropServices
Public Module Beeps
Public Sub WindowsBeep()
Interaction.Beep()
End Sub
Public Sub ForceBeep()
Beep(900, 300)
End Sub
<DllImport("Kernel32.dll")> _
Private Function Beep(ByVal frequency As UInt32, ByVal duration As UInt32) As Boolean
End Function
End Module
- Tools => Macros => Macros IDE
- My Macros (In Project Explorer) => Add New Module => Name: "Beeps"
- Copy the above code in. It has 2 methods
- First one uses the windows "Beep" sound
- Second one forces a "Beep" tone, not a .wav file. This works with all sounds disabled (eg Control Panel -> Sounds -> Sound Scheme: No Sounds), but sounds ugly.
- View the Macro Explorer in VS.Net (not the macro IDE) to make sure it is there :)
- 工具 => 宏 => 宏 IDE
- 我的宏(在项目资源管理器中)=> 添加新模块 => 名称:“Beeps”
- 把上面的代码复制进去,有2个方法
- 第一个使用Windows“Beep”声音
- 第二个强制发出“哔”声,而不是 .wav 文件。这适用于禁用所有声音(例如控制面板 -> 声音 -> 声音方案:无声音),但听起来很难看。
- 在 VS.Net(不是宏 IDE)中查看宏资源管理器以确保它在那里:)
Assign To A Breakpoint
分配给断点
- Add a break point to a line
- Right click on the little red dot
- Select "When Hit"
- Check the box to enable macros
- Select your macro from the pulldown
- Uncheck"continue execution" if you want to stop. It is checked by default.
- 给一行添加一个断点
- 右击小红点
- 选择“命中时”
- 选中该框以启用宏
- 从下拉菜单中选择您的宏
- 如果要停止,请取消选中“继续执行”。默认情况下是选中的。
Also, there areways to play an arbitrary wav file, but that seems excessive for an alert. Perhaps the forced "beep" is the best, since that at least soundsdifferent than Ding.
此外,还有一些方法可以播放任意 wav 文件,但这对于警报来说似乎太过分了。或许强制的“哔”声是最好的,因为那至少听起来和“叮”不一样。
回答by 1800 INFORMATION
You can create a macro that runs in response to a breakpoint firing. In your macro, you could do whatever it takes to make a beeping noise.
您可以创建一个响应断点触发而运行的宏。在你的宏中,你可以做任何事情来发出哔哔声。

