Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   Help With WaitHandle.WaitAll() (http://www.go4expert.com/forums/help-with-waithandlewaitall-t5964/)

Andrew777 21Aug2007 17:47

Help With WaitHandle.WaitAll()
 
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 21Aug2007 17:49

Re: Help With WaitHandle.WaitAll()
 
Sorry,
This Line

Tasks(2) = New AutoResetEvent(False)

is not supposed to be there, just ignore it.


All times are GMT +5.5. The time now is 04:50.