skip to main | skip to sidebar

Breaking Builds Since 2008

Pages

  • Home

Thursday, 18 August 2011

Attach to .NET worker process

If you are sick of how much effort it takes to attach the Visual Studio debugger to a process in then try out this macro.  With one click it will find all the .NET worker processes running on your machine and attach to them all.

This is based on the code found here: http://blog.lavablast.com/post/2008/01/11/Attach-to-Process-with-one-shortcut.aspx

This is tested in Visual Studio 2008 and 2010.


Public Module AttachDebugger
    Public Sub AttachDebugger()
        Try
 
            Dim count As Integer
            count = 0
 
            Dim process As EnvDTE.Process
 
            For Each process In DTE.Debugger.LocalProcesses
                If IsTargetedProcess(process) Then
                    process.Attach()
                    count = count + 1
                End If
            Next
 
            If count > 0 Then
                MsgBox("Successfully connected to " & count & " processes.")
            Else
                MsgBox("No targeted processes found.")
            End If
 
        Catch ex As System.Exception
            MsgBox("Error: " & ex.Message)
        End Try
    End Sub
 
    Private Function IsTargetedProcess(ByVal process As EnvDTE.Process) As Boolean
 
        If process.Name.EndsWith("w3wp.exe") Then
            Return True
        ElseIf process.Name.EndsWith("aspnet_wp.exe") Then
            Return True
            'List any other processes you might commonly attach to
        ElseIf process.Name.EndsWith("NServiceBus.Host.exe") Then
            Return True
        End If
 
        Return False
 
    End Function
End Module
Posted by Mike at 08:54 Email This BlogThis! Share to X Share to Facebook
Labels: Visual-Studio

1 comments:

Unknown said...

Like it!

18 August 2011 at 14:06

Post a Comment

Newer Post Older Post Home

About Me

Mike
Keen on all things C#.
View my complete profile

Blog Archive

  • ►  2014 (1)
    • ►  July (1)
  • ►  2013 (1)
    • ►  August (1)
  • ►  2012 (1)
    • ►  March (1)
  • ▼  2011 (5)
    • ▼  August (2)
      • Attach to .NET worker process
      • Construction complete
    • ►  July (3)

Followers

Powered by Blogger.
 
Copyright (c) 2010 Breaking Builds Since 2008. Designed for Video Games
Download Christmas photos, Public Liability Insurance, Premium Themes