最初にタイマーを初期化し、コマンド Exception.Debug を呼び出します。モーダル ダイアログが開いているときにタイマーがヒットしました。非アクティブ化されたUAC SendKeysでALTキーを使用してWin 7を使用すると失敗します...理由はわかりません。
私は少しプレイしました...これを試してください(VS2010 EN):
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Imports System.Runtime.InteropServices
'...
Private WithEvents t As Timers.Timer
Private Sub t_Elapsed(ByVal ee As Object, ByVal dd As Timers.ElapsedEventArgs) Handles t.Elapsed
t.Stop()
' Tastatureingaben simulieren
System.Windows.Forms.SendKeys.SendWait("{DOWN}")
System.Threading.Thread.Sleep(1500) ' Pause wichtig zum Laden des Exceptionbaums
System.Windows.Forms.SendKeys.SendWait("%t")
System.Windows.Forms.SendKeys.SendWait("{ENTER}")
End Sub
Public Sub toggleCLRExceptions()
If DTE.Solution.Count <= 0 Then
MsgBox("Nicht ohne geöffnete Solution!")
Exit Sub
End If
' Timer wird benötigt, da der Dialog Modal ist
' und weitere Befehle im Macro werden erst nach beenden des Dialogs ausgeführt
t = New Timers.Timer()
t.Interval = 0.5
t.Start()
DTE.ExecuteCommand("Debug.Exceptions")
'System.Windows.Forms.SendKeys.SendWait("^%e") ' alternativ: STRG+ALT+e
System.Threading.Thread.Sleep(200)
If isCLRExceptionsActive() Then
MsgBox("BREAK @CLR-Exception", MsgBoxStyle.Information, "Info")
Else
MsgBox("NO BREAK @CLR-Exception", MsgBoxStyle.Information, "Info")
End If
End Sub
Function isCLRExceptionsActive() As Boolean
' prüft, ob Setting Debug CLR-Exceptions aktiviert/deaktivert ist
Dim dbg As EnvDTE100.Debugger5 = DTE.Debugger
Dim exSettings As ExceptionSettings = dbg.ExceptionGroups.Item("Common Language Runtime Exceptions")
Dim exSetting As ExceptionSetting
Try
exSetting = exSettings.Item("Common Language Runtime Exceptions")
Catch ex As COMException
If ex.ErrorCode = -2147352565 Then
exSetting = exSettings.NewException("Common Language Runtime Exceptions", 0)
End If
End Try
Return exSetting.BreakWhenThrown
End Function
'...