Avatar of Quentin Bédarride
Quentin Bédarride
 asked on

Running a function in a new thread

Hello, this function is making the whole program to freeze when it's working, so I would like to put it in another thread.
The problem is I don't know how to make it work in another thread because of the arguments and to return the value.
Can you help me ?
    Function SearchForFiles(ByVal RootFolder As String, ByVal FileFilter() As String) As List(Of String)
        Dim ReturnedData As New List(Of String)                            
        Dim FolderStack As New Stack(Of String)                             
        FolderStack.Push(RootFolder)                                        
        Do While FolderStack.Count > 0                                      
            Dim ThisFolder As String = FolderStack.Pop                      
            Try                                                             
                For Each SubFolder In GetDirectories(ThisFolder)            
                    FolderStack.Push(SubFolder)                             
                Next                                                        
                For Each FileExt In FileFilter                              
                    ReturnedData.AddRange(GetFiles(ThisFolder, FileExt))    
                Next                                                        
            Catch ex As Exception                                          
            End Try                                                         
        Loop                                                                
        Return ReturnedData                                                 
    End Function

Open in new window

Visual Basic.NET* multithreading

Avatar of undefined
Last Comment
Fernando Soto

8/22/2022 - Mon
DevAdmin

Quentin Bédarride

ASKER
The problem for me is to use the multiple arguments required for this function with a backgroundworker, can you give me an example ?
ASKER CERTIFIED SOLUTION
Fernando Soto

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Quentin Bédarride

ASKER
Thank you Fernando Soto, I followed your example and it works perfectly !
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Fernando Soto

Not a problem Quentin Bédarride, glad I was able to help.