Я новичок в мире VB.NET, и мне было поручено собрать небольшую программу для поиска в каталоге из примерно 2000 электронных таблиц Excel и собрать список для отображения на основе значения пользовательского свойства документа внутри файл электронной таблицы. Учитывая, что я далеко не программист по образованию или профессии, это было приключение.
Я получил его на работу, результаты в порядке. Проблема в том, что для запуска требуется более минуты. Он запускается через подключение к локальной сети. Когда я запускаю его локально (используя «тестовый» каталог из примерно 300 файлов), он выполняется примерно за 4 секунды.
Я даже не уверен, чего ожидать от разумной скорости выполнения, поэтому я подумал, что задам вопрос здесь.
Код ниже, если кто-то думает, что изменения могут быть полезны для ускорения.
Заранее спасибо!
Private Sub listByPt()
Dim di As New IO.DirectoryInfo(dir_loc)
Dim aryFiles As IO.FileInfo() = di.GetFiles("*" & ext_to_check)
Dim fi As IO.FileInfo
Dim dso As DSOFile.OleDocumentProperties
Dim sfilename As String
Dim sheetInfo As Object
Dim sfileCount As String
Dim ifilesDone As Integer
Dim errorList As New ArrayList()
Dim ErrorFile As Object
Dim ErrorMessage As String
'Initialize progress bar values
ifilesDone = 0
sfileCount = di.GetFiles("*" & ext_to_check).Length
Me.lblHighProgress.Text = sfileCount
Me.lblLowProgress.Text = 0
With Me.progressMain
.Maximum = di.GetFiles("*" & ext_to_check).Length
.Minimum = 0
.Value = 0
End With
'Loop through all files in the search directory
For Each fi In aryFiles
dso = New DSOFile.OleDocumentProperties
sfilename = fi.FullName
Try
dso.Open(sfilename, True)
'grab the PT Initials off of the logsheet
Catch excep As Runtime.InteropServices.COMException
errorList.Add(sfilename)
End Try
Try
sheetInfo = dso.CustomProperties("PTNameChecker").Value
Catch ex As Runtime.InteropServices.COMException
sheetInfo = "NONE"
End Try
'Check to see if the initials on the log sheet
'match those we are searching for
If sheetInfo = lstInitials.SelectedValue Then
Dim logsheet As New LogSheet
logsheet.PTInitials = sheetInfo
logsheet.FileName = sfilename
PTFiles.Add(logsheet)
End If
'update progress bar
Me.progressMain.Increment(1)
ifilesDone = ifilesDone + 1
lblLowProgress.Text = ifilesDone
dso.Close()
Next
lstResults.Items.Clear()
'loop through results in the PTFiles list
'add results to the listbox, removing the path info
For Each showsheet As LogSheet In PTFiles
lstResults.Items.Add(Path.GetFileNameWithoutExtension(showsheet.FileName))
Next
'build error message to display to user
ErrorMessage = ""
For Each ErrorFile In errorList
ErrorMessage += ErrorFile & vbCrLf
Next
MsgBox("The following Log Sheets were unable to be checked" _
& vbCrLf & ErrorMessage)
PTFiles.Clear() 'empty PTFiles for next use
End Sub