English 中文(简体)
用视觉演播室宏观书写现有文件的速度极慢,建议加快速度?
原标题:Writing to current document with a visual studio macro is extremely slow, suggestions to speedup?

总的来说,我没有就视觉演播室的速度提出任何抱怨,但如果我写出一个写出大约100条代码的宏观节目,则需要1-2分钟的时间才能完成。

这一权利是正确的。 是否还有更方便的方法来书写密码区块?

一次,我注意到,它填补了无休止的缓冲,就像我手打字案文一样。 我是否真的照样照样/做事,这种行动要快得多?

在此,我试图检验我的案件,这是一个有争议的例子:

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
最佳回答

本份标书非常令人接受,因为看来你正在以<代码”的实际结果取代选定的案文。 StringBuilder。 简言之,一份副本/过去。 但是,你重新做的是打上了<代码>StringBuilder的成果(这就是为什么你看到了用数据填补的无实缓冲)。

对于从DTE名称空间获得的许多编辑经验来说,这类行为是真实的。 如果你对讲解细节感兴趣,我就在一段时间前就曾写过有关这一一般性问题的博客经验。

为了确定这一标准,你希望放弃电离层,并登入<条码>四舍五入/条码>或<条码>。 (后者较新人管理的APIC) 离开情报和安全局,你应能执行以下任务:

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

载于<代码>IVsTextLines的电子设备将直接投向缓冲器,避免打字的间接费用。

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.

问题回答
   SLOOOW!
   DTE.ActiveDocument.Selection.Text = str
   LIGHTNING FAST
   Dim txtSel As TextSelection
   txtSel = DTE.ActiveDocument.Selection
   txtSel.Delete()
   txtSel.Insert(str, vsInsertFlags.vsInsertFlagsInsertAtEnd)

I was facing the same problem as Abel, And thanks to JaredPar hints I was able to fix it in this way: Instead of using IVsTextLines (Which seem to be only available when you have VS-SDK installed) I just use TextDocumentand get the EditPoint object from that. My code look like this:

Dim vsTextDoc As TextDocument = DTE.ActiveDocument.Object("TextDocument")
Dim epoint As EditPoint = vsTextDoc.StartPoint.CreateEditPoint
Dim strBuilder As StringBuilder = New StringBuilder

 append everything to the strBuilder and then
strBuilder.AppendLine("This is a line")
epoint.Insert(strBuilder.ToString())

而且 现在,它感到快要与此前发生的任何情况相比:TE.ActiveDocument.Selection.Text! 希望未来将有助于:





相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签