all groups > visual studio .net ide > april 2004 >
You're in the

visual studio .net ide

group:

Iterating project files seems very slow...



Iterating project files seems very slow... Andrew Hilton
4/30/2004 2:56:05 PM
visual studio .net ide: Hello,

We have a lot of files in different directories in our project. I wrote a
macro to find and open a source file based on the filename rather than using
the solution explorer. But it's so slow as to be unusable. Is there
something obvious in my code, or is there another way to do this?

Andrew

Public Sub FindFile()

Dim ps As ProjectItems =
ActiveDocument.ProjectItem.ContainingProject.ProjectItems

Dim s As String = InputBox("Enter part of the filename to open.", "Open
File")

Dim re As New Regex(s, RegexOptions.IgnoreCase)

If s = "" Then Exit Sub

If Not IterateProjectItems(ps, re, s) Then MsgBox("No matching files
found")

End Sub



Private Function IterateProjectItems(ByRef ps As ProjectItems, ByRef re As
Regex, ByVal s As String)

Dim pi As ProjectItem

Dim found As Boolean

For Each pi In ps

If re.IsMatch(pi.Name) Then

found = True

pi.Open()

pi.Document.Activate()

End If

found = IterateProjectItems(pi.ProjectItems, re, s) Or found

Next

IterateProjectItems = found

End Function

Re: Iterating project files seems very slow... Carlos J. Quintero [MVP]
5/4/2004 12:16:05 PM
Basically your code is right expect a couple of details not related to
performance:

1) Dim ps As ProjectItems =
ActiveDocument.ProjectItem.ContainingProject.ProjectItems

This will cause exception if there is no document open.

2) pi.Open()
pi.Document.Activate()

Maybe not all ProjectIems has a Document, so this statement can fail too.
Use instead:

Dim objWindow As Window

objWindow = pi.Open()
objWindow.Visible = True

About performance, if you move the code from a macro into a compiled addin,
it should fly faster.

--

Carlos J. Quintero (Visual Developer - .NET MVP)

FAQs, Knowledge Base, Files, Docs, Articles, Utilities, etc. for .NET
addins:
http://groups.yahoo.com/group/vsnetaddin/ (free join)



"Andrew Hilton" <hiltona@ocean.com.au> escribió en el mensaje
news:OPLWh9mLEHA.3892@TK2MSFTNGP11.phx.gbl...
[quoted text, click to view]

Re: Iterating project files seems very slow... Andrew Hilton
5/10/2004 2:13:33 PM
Carlos,

Thank you for your tips. A compiled add-in makes a lot more sense. After
some thought here we realised the same thing could be achieved by opening
the project file into a xml dom and searching for the files using xpath
(although I have yet to do any xml processing using .net). That would be a
lot quicker and still achieveable within the macro environment. If I ever
get around to coding it - I will post it here. Forgot to mention we're using
vsnet 2001, maybe macro performance has improved in the latest version.

Andrew

[quoted text, click to view]

AddThis Social Bookmark Button