Link to home
Create AccountLog in
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

Avatar of DevAdmin
DevAdmin
Flag of Italy image

Avatar of Quentin Bédarride
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
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thank you Fernando Soto, I followed your example and it works perfectly !
Not a problem Quentin Bédarride, glad I was able to help.