-1

I'm creating a Visual Studio 2013 plugin (ok, extension package actually) that seeks to paste certain strings* into a currently open .vb or .cs file, but when I get to the point of doing the actual pasting of text the editor instance freezes up for a while. If there are reletively few lines, VS will come back after a few seconds, but for 20+ lines the editor just never comes back.

This is the gist of what my code looks like:

String myText = "foo";

DTE dte = this.GetService(typeof(DTE)) as DTE;
EnvDTE.TextSelection selection = (dte.ActiveDocument.Selection as EnvDTE.TextSelection);

selection.Text = "";

//Here myText ends up having some content written into it

selection.Text = myText; //VS hangs after this point

Any clues as to what I can do to fix (or at least debug) this? I've tried VS's Profiler but all I get is that 98% of the time is wasted on "msenv.dll" and I can't see what's going on inside..

*(takes SQL from the clipboard and breaks it into lines wrapped in AppendLine calls to a StringBuilder)

Sebastián Vansteenkiste
  • 2,234
  • 1
  • 19
  • 29
  • which line is it hanging on when you step thru the code is it this line `GetService` have you read the documentation https://msdn.microsoft.com/en-us/library/envdte.textselection.aspx – MethodMan Mar 01 '16 at 18:09
  • No.. It's on the last line of the code, like it says in my example.. Thanks. – Sebastián Vansteenkiste Mar 01 '16 at 18:15
  • I don't see any string builder code.. why are you not showing all relevant code..? – MethodMan Mar 01 '16 at 18:19
  • Because that text would be on the file where I would paste my text. I'm just anecdotically telling what the purpose of the extension is, but the contents of the pasted text are irrelevant to the issue. The only problem here truly is that use of `selection.Text = myText;` is too slow, so `selection.Insert(myText);` should be used instead. – Sebastián Vansteenkiste Mar 01 '16 at 18:26

1 Answers1

1

OK, I hadn't seen this question: https://stackoverflow.com/a/1096737/1605873

Turns out, I just needed to use selection.Insert(myText); rather than selection.Text = myText; it is absurdly faster.

Community
  • 1
  • 1
Sebastián Vansteenkiste
  • 2,234
  • 1
  • 19
  • 29