Home All Groups Group Topic Archive Search About
Author
21 Dec 2006 7:44 PM
Carly
Hi,

I have the following code:

Imports System.Threading
Module Module1

    Sub Main()
        Dim mydel As New WaitCallback(AddressOf Showmytext)
        ThreadPool.QueueUserWorkItem(mydel)
        ThreadPool.QueueUserWorkItem(mydel)
        ThreadPool.QueueUserWorkItem(mydel)
        Console.Read()



    End Sub
    Sub Showmytext(ByVal state As Object)
        Dim mystr As String = CType(state, String)
        Console.Write(Thread.CurrentThread.ManagedThreadId)
        Dim i As Integer
        Dim j As Long
        For i = 1 To 10000
            j = 0
            j = 10000 * 123456

        Next
        Thread.Sleep(1000)
        Console.Write(j)
    End Sub


End Module

All my code runs in the SAME thread and runs... synchronously meaning
it ways for the first for i-----sleeps then writes the result on the
console , moves to the next.... etc.

Please somebody explain why.

Thanks,

Carly

Author
21 Dec 2006 8:00 PM
Lucian Wischik
"Carly" <carl.j***@hotmail.com> wrote:
>All my code runs in the SAME thread and runs... synchronously meaning
>it ways for the first for i-----sleeps then writes the result on the
>console , moves to the next.... etc.
>Please somebody explain why.

I just ran your code and it used two threads in the pool.

Then I increased the Sleep to Sleep(10000) and it used three threads
in the pool.


--
Lucian