Help With WaitHandle.WaitAll()

Andrew777's Avatar, Join Date: Aug 2007
Newbie Member
Hello,

I am trying to create a program that executes threads, waits until they are finished and then executes some more code.
When I run it, I recieve a "Object not set to an instance" error on WaitHandle.WaitAll(Tasks). Why does this occur?, WaitHandle.WaitAll is a static method.

Hope someone can help


Code:
Module Module1

Dim Tasks(1) As AutoResetEvent

<MTAThread()> Sub Main()
        Tasks(0) = New AutoResetEvent(False)
        Tasks(1) = New AutoResetEvent(False)
        Tasks(2) = New AutoResetEvent(False)

        ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf T1), Tasks(0))
        ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf T2), Tasks(1))

         WaitHandle.WaitAll(Tasks)
        ' Do some Tasks
    End Sub
   
    Sub T1(ByVal state As Object)
        System.Console.Write("In T1")
        Thread.Sleep(3000)
        Tasks(0).Set()
    End Sub

    Sub T2(ByVal state As Object)
         System.Console.Write("In T2")
         Thread.Sleep(3000)
         Tasks(1).Set()
    End Sub

End Module
Andrew777's Avatar, Join Date: Aug 2007
Newbie Member
Sorry,
This Line

Tasks(2) = New AutoResetEvent(False)

is not supposed to be there, just ignore it.