Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7041779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:05:16+00:00 2026-05-28T02:05:16+00:00

Generally I’ve no complaints about the speed of Visual Studio, but if I write

  • 0

Generally I’ve no complaints about the speed of Visual Studio, but if I write a macro that writes out about 100 lines of code, it takes 1-2 minutes to complete.

That doesn’t sound right. Is there another more convenient way to write code blocks?

For one thing, I noticed it fills the undo buffer as if I’m just typing the text by hand. Could I mimic copy/paste behavior, which is much faster?

Here’s a somewhat contrived example I tried to test my case:

Sub WriteManyLines()
    DTE.Commands.Raise("{AA61C329-D559-468F-8F0F-4F03896F704D}", 2, Customin, Customout)
    DTE.Commands.Raise("{AA61C329-D559-468F-8F0F-4F03896F704D}", 5, Customin, Customout)
    Dim sb As New StringBuilder()

    For i As Integer = 1 To 100
        sb.AppendFormat("public string Method{0:000}() {{ return ""Method{0:000}""; }}", i)
        sb.AppendLine()
    Next i
    DTE.ActiveDocument.Selection.Text = sb.ToString()
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:05:17+00:00Added an answer on May 28, 2026 at 2:05 am

    This API is very deceptive in that it appears that you are replacing the selected text with the actual result of the StringBuilder. Or in short, a copy / paste. But what you’re really doing is typing the result of the StringBuilder (this is why you seen the undo buffer filling up with data).

    This type of behavior is true for much of the editing experience which comes from the DTE namespace. If you’re interested in the esoteric details I wrote a blog experience about this general problem some time ago.

    • http://blogs.msdn.com/b/jaredpar/archive/2010/06/10/avoiding-automation-bugs-when-implementing-iolecommandtarget.aspx

    In order to fix it though you’ll want to abandon DTE and get down into IVsTextLines or ITextBuffer (the latter is preferred as it’s the newer managed API). To get out of DTE you should be able to execute the following

    var vsTextLines = DTE.ActiveDocument.Object("TextDocument") as IVsTextLines;
    

    Edits on an IVsTextLines will go directly to the buffer and avoid the overhead of typing.

    If you want to avoid DTE and COM entirely you can use IVsEditorAdaptersFactoryService to map from the COM layer to the new 2010 managed APIs. This interface is typically queried via MEF but I believe you can also use IServiceProvider (which DTE implements) and do a QueryService call for it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Generally speaking, the SQL queries that I write return unformatted data and I leave
Generally I use lxml for my HTML parsing needs, but that isn't available on
Generally speaking, when given a cookie that has no expiration period, modern browsers will
Generally it appears preferable in C++ that code that functions that take a parameter
Generally I seem to be able to fix IE problems nowadays.. but this one
Generally We have some business logic that is causing a bottle neck within a
Generally we traverse the array by row or column but here I want to
Generally UDP doesn't garantee that packets will arrive in the same order they were
Generally speaking - is it possible to draw with javascript two diagonal lines inside
Generally if there is a property that gets/sets a value for state, I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.