Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

c# - Attaching to a child process automatically in Visual Studio during Debugging

When writing plugins for media center your plugin is hosted in ehexthost.exe this exe gets launched from ehshell.exe and you have no way of launching it directly, instead you pass a special param to ehshell.exe which will launch the plugin in a separate process.

When we are debugging media browser I find the process of attaching to a second process kind of clunky, I know about Debugger.Attach and also of some special registry entries I can use.

Both these methods don't exactly fit my bill. What I want is to press F5 and have my current instance of visual studio attach to the child process automatically. Can this be done?

If there is a plugin for VS that allows me to achieve this functionality I would be happy with it.

EDIT

I ended up going with the following macro:

Public Sub CompileRunAndAttachToEhExtHost()

    DTE.Solution.SolutionBuild.Build(True)
    DTE.Solution.SolutionBuild.Debug()

    Dim trd As System.Threading.Thread = New System.Threading.Thread(AddressOf AttachToEhExtHost)
    trd.Start()

End Sub

Public Sub AttachToEhExtHost()
    Dim i As Integer = 0
    Do Until i = 50
        i = i + 1
        Try

            For Each proc As EnvDTE.Process In DTE.Debugger.LocalProcesses
                If (proc.Name.IndexOf("ehexthost.exe") <> -1) Then
                    proc.Attach()
                    Exit Sub
                End If
            Next
        Catch e As Exception
            ' dont care - stuff may be busy 
        End Try
        Threading.Thread.Sleep(100)
    Loop
End Sub

Also, I outlined the process on how to get this going on my blog.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would use a macro. I've redefined my F5 function to attach to the asp.net process instead of the long build/validate it usually performs. This works pretty well for me and it's really easy.

    For Each process In DTE.Debugger.LocalProcesses
        If (process.Name.IndexOf("aspnet_wp.exe") <> -1) Then
            process.Attach()
            Exit Sub
        End If
    Next

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...