hi,
I wanted to get the directories in a specific path
and I wrote that by threading programming
but when I call

waithandle.waitall(mywaithandles)

, I get the
unhandled exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
Additional information: Value cannot be null.
error.

Can anyone help me what to do ?
there is my code of this part:

<MTAThread()> Public Sub file_search()
       
            Dim DD() As String = Directory.GetDirectories(Searcher_path)
            Dim num_of_dirs As Integer = get_unemptyfolders_num(DD)
            Dim mywaithandles(num_of_dirs) As AutoResetEvent
               For i As Integer = 0 To DD.Length - 1
                If is_emty(DD(i))=false Then
                    num_of_dirs -= 1
                    mywaithandles(num_of_dirs) = New AutoResetEvent(False)
                    Dim th_info As Threadinfo = New Threadinfo(DD(i), mywaithandles(num_of_dirs))
                    ThreadPool.QueueUserWorkItem(AddressOf searcher_thread, th_info)
                End If
            Next
            WaitHandle.WaitAll(mywaithandles)
end sub

According to your code, the mywaithandles(0) may have no handle info at all.

I would suggest to sligly change your code to this untested example:

<MTAThread()> Public Sub file_search()
    Dim DD() As String = Directory.GetDirectories(Searcher_path)
    Dim mywaithandles() As AutoResetEvent = Nothing
    Dim currentHandleIdx as Integer = -1
    For i As Integer = 0 To DD.Length - 1
        If is_emty(DD(i))=false Then
            If mywaithandles Is Nothing Then
                ReDim mywaithandles(0)
            Else
                ReDim Preserve mywaithandles(mywaithandles.Length)
            End If
            currentHandleIdx = mywaithandles.Length -1
            mywaithandles(currentHandleIdx) = New AutoResetEvent(False)
            Dim th_info As Threadinfo = New Threadinfo(DD(i), mywaithandles(currentHandleIdx))
            ThreadPool.QueueUserWorkItem(AddressOf searcher_thread, th_info)
        End If
    Next
    If Not mywaithandles Is Nothing then WaitHandle.WaitAll(mywaithandles)
end sub

Hope this helps

thanks for your reply lola
but I got my mistake that was too obvious
I had searched all folders,even ones that hadn't permission to access
since that was in a try, I couldn't find it
my waithandles became null in that way

anyway thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.