Index Files and then Search Index Efficient

Marc Menzel 101 Reputation points
2025-04-24T01:14:52.99+00:00

I am attempting to build a file command index for searching. I have the following code; however it consumes system resources and freezes the program at times.

`Private Sub ListBackgroundWorker_DoWork(sender As Object, e As DoWorkEventArgs) Handles ListBackgroundWorker.DoWork`
````        Dim SelectedCommandListString As List(Of String) = New List(Of String)`

`        Dim SelectedCommandListItem As String = ""`

`        Dim EnteredCommandText As String = CType(e.Argument, String)`

`        If CommandListBoxMode = CommandListType.File Then`

`            ' Filter the CombinedList based on the entered command text`

`            SelectedCommandList = SearchFileList.Where(Function(x) _`

`                                        ((x.FileName.StartsWith(EnteredCommandText, StringComparison.OrdinalIgnoreCase) = True))).ToList`

`        Else`

`            SelectedCommandList = CombinedList.Where(Function(x) _`

`                                        ((x.FileName.StartsWith(EnteredCommandText) = True))).ToList`

`        End If`

`        SelectedCommandListString = SelectedCommandList.Select(Function(x) If(x.FilePath <> "None", x.FileName & " " & x.FilePath, x.FileName)).Where(Function(x) x IsNot Nothing).ToList()`

`        ' Pass the results to the RunWorkerCompleted event`

`        e.Result = SelectedCommandListString`

`    End Sub`

Is there a more efficient way of accomplishing this?
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,837 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.