Visual Studio: How to trigger an alarm when a breakpoint is hit?

倾然丶 夕夏残阳落幕 提交于 2019-12-17 18:15:03

问题


Is there a way to trigger a beep/alarm/sound when my breakpoint is hit? I'm using Visual Studio 2005/2008.


回答1:


Windows XP

Control Panel -> Sounds and Audio... -> Program Events - Microsoft Developer -> Breakpoint Hit

Windows 7

Control Panel -> All Control Panel Items -> Sounds -> Sounds (tab) - Microsoft Visual Studio -> Breakpoint Hit




回答2:


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:

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
  1. Tools => Macros => Macros IDE
  2. My Macros (In Project Explorer) => Add New Module => Name: "Beeps"
  3. Copy the above code in. It has 2 methods
    1. First one uses the windows "Beep" sound
    2. 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.
  4. View the Macro Explorer in VS.Net (not the macro IDE) to make sure it is there :)

Assign To A Breakpoint

  1. Add a break point to a line
  2. Right click on the little red dot
  3. Select "When Hit"
  4. Check the box to enable macros
  5. Select your macro from the pulldown
  6. Uncheck "continue execution" if you want to stop. It is checked by default.

Also, there are ways to play an arbitrary wav file, but that seems excessive for an alert. Perhaps the forced "beep" is the best, since that at least sounds different than Ding.




回答3:


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.



来源:https://stackoverflow.com/questions/80564/visual-studio-how-to-trigger-an-alarm-when-a-breakpoint-is-hit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!