Home All Groups Group Topic Archive Search About
Author
1 Jun 2006 3:19 PM
fniles
I am using thread (sub ThreadMain in the ClientSession class). I call it
from main application called MainForm.
Inside ThreadMain, I call a subroutine WriteLine from the MainForm.
Will WriteLine run/processed inside or outside the thread ?

Thanks.

Code from main appl:
Public Class MainForm
Private Session As ClientSession = Nothing

        ' Create a new instance of the ClientSession object and a worker
        ' thread that will handle the socket I/O
        Session = New ClientSession
        WorkerThread = New Threading.Thread(AddressOf Session.ThreadMain)

        ' Initialize the client session object with the reference to
        ' this form, and the socket that was created
        Session.ClientForm = Me

        ' Initialize the worker thread and start its execution
        ' WorkerThread.ApartmentState = Threading.ApartmentState.STA
        WorkerThread.Name = "WorkerThread"
        WorkerThread.Start()

Public Sub WriteLine(ByVal Line As String)
:
end sub

Code from inside thread:
Public Class ClientSession
    Public ClientForm As MainForm = Nothing

Public Sub ThreadMain()
:
ClientForm.WriteLine(strBuffer)

Author
2 Jun 2006 3:41 PM
Mike Lowery
Anything invoked in a Thread should run inside that thread.  It's analogous to
launching a separate application.

Show quoteHide quote
"fniles" <fni***@pfmail.com> wrote in message
news:uZzF4glhGHA.3904@TK2MSFTNGP02.phx.gbl...
>I am using thread (sub ThreadMain in the ClientSession class). I call it from
>main application called MainForm.
> Inside ThreadMain, I call a subroutine WriteLine from the MainForm.
> Will WriteLine run/processed inside or outside the thread ?
>
> Thanks.
>
> Code from main appl:
> Public Class MainForm
> Private Session As ClientSession = Nothing
>
>        ' Create a new instance of the ClientSession object and a worker
>        ' thread that will handle the socket I/O
>        Session = New ClientSession
>        WorkerThread = New Threading.Thread(AddressOf Session.ThreadMain)
>
>        ' Initialize the client session object with the reference to
>        ' this form, and the socket that was created
>        Session.ClientForm = Me
>
>        ' Initialize the worker thread and start its execution
>        ' WorkerThread.ApartmentState = Threading.ApartmentState.STA
>        WorkerThread.Name = "WorkerThread"
>        WorkerThread.Start()
>
> Public Sub WriteLine(ByVal Line As String)
> :
> end sub
>
> Code from inside thread:
> Public Class ClientSession
>    Public ClientForm As MainForm = Nothing
>
> Public Sub ThreadMain()
> :
> ClientForm.WriteLine(strBuffer)
>
>
>
Author
1 Jun 2006 9:16 PM
fniles
Thanks.
I just want to make sure.
So, even though the code for WriteLine is inside MainForm, but since it is
called from ThreadMain, it will run inside the thread, right ?

Thanks.

Show quoteHide quote
"Mike Lowery" <selfspam@mouse-potato.com> wrote in message
news:O8FM0rlhGHA.3584@TK2MSFTNGP04.phx.gbl...
> Anything invoked in a Thread should run inside that thread.  It's
> analogous to launching a separate application.
>
> "fniles" <fni***@pfmail.com> wrote in message
> news:uZzF4glhGHA.3904@TK2MSFTNGP02.phx.gbl...
>>I am using thread (sub ThreadMain in the ClientSession class). I call it
>>from main application called MainForm.
>> Inside ThreadMain, I call a subroutine WriteLine from the MainForm.
>> Will WriteLine run/processed inside or outside the thread ?
>>
>> Thanks.
>>
>> Code from main appl:
>> Public Class MainForm
>> Private Session As ClientSession = Nothing
>>
>>        ' Create a new instance of the ClientSession object and a worker
>>        ' thread that will handle the socket I/O
>>        Session = New ClientSession
>>        WorkerThread = New Threading.Thread(AddressOf Session.ThreadMain)
>>
>>        ' Initialize the client session object with the reference to
>>        ' this form, and the socket that was created
>>        Session.ClientForm = Me
>>
>>        ' Initialize the worker thread and start its execution
>>        ' WorkerThread.ApartmentState = Threading.ApartmentState.STA
>>        WorkerThread.Name = "WorkerThread"
>>        WorkerThread.Start()
>>
>> Public Sub WriteLine(ByVal Line As String)
>> :
>> end sub
>>
>> Code from inside thread:
>> Public Class ClientSession
>>    Public ClientForm As MainForm = Nothing
>>
>> Public Sub ThreadMain()
>> :
>> ClientForm.WriteLine(strBuffer)
>>
>>
>>
>
>
Author
5 Jun 2006 3:13 PM
Mike Lowery
Unless I'm missing something, it should.

Show quoteHide quote
"fniles" <fni***@pfmail.com> wrote in message
news:%23PE8k4IiGHA.1264@TK2MSFTNGP05.phx.gbl...
> Thanks.
> I just want to make sure.
> So, even though the code for WriteLine is inside MainForm, but since it is
> called from ThreadMain, it will run inside the thread, right ?
>
> Thanks.
>
> "Mike Lowery" <selfspam@mouse-potato.com> wrote in message
> news:O8FM0rlhGHA.3584@TK2MSFTNGP04.phx.gbl...
>> Anything invoked in a Thread should run inside that thread.  It's
>> analogous to launching a separate application.
>>
>> "fniles" <fni***@pfmail.com> wrote in message
>> news:uZzF4glhGHA.3904@TK2MSFTNGP02.phx.gbl...
>>>I am using thread (sub ThreadMain in the ClientSession class). I call it
>>>from main application called MainForm.
>>> Inside ThreadMain, I call a subroutine WriteLine from the MainForm.
>>> Will WriteLine run/processed inside or outside the thread ?
>>>
>>> Thanks.
>>>
>>> Code from main appl:
>>> Public Class MainForm
>>> Private Session As ClientSession = Nothing
>>>
>>>        ' Create a new instance of the ClientSession object and a worker
>>>        ' thread that will handle the socket I/O
>>>        Session = New ClientSession
>>>        WorkerThread = New Threading.Thread(AddressOf Session.ThreadMain)
>>>
>>>        ' Initialize the client session object with the reference to
>>>        ' this form, and the socket that was created
>>>        Session.ClientForm = Me
>>>
>>>        ' Initialize the worker thread and start its execution
>>>        ' WorkerThread.ApartmentState = Threading.ApartmentState.STA
>>>        WorkerThread.Name = "WorkerThread"
>>>        WorkerThread.Start()
>>>
>>> Public Sub WriteLine(ByVal Line As String)
>>> :
>>> end sub
>>>
>>> Code from inside thread:
>>> Public Class ClientSession
>>>    Public ClientForm As MainForm = Nothing
>>>
>>> Public Sub ThreadMain()
>>> :
>>> ClientForm.WriteLine(strBuffer)
>>>
>>>
>>>
>>
>>
>
>
>
Author
5 Jun 2006 4:03 PM
Brian Gideon
fniles wrote:
> Thanks.
> I just want to make sure.
> So, even though the code for WriteLine is inside MainForm, but since it is
> called from ThreadMain, it will run inside the thread, right ?
>

Yes, that is correct.
Author
4 Jun 2006 4:30 PM
fniles
Thank you all.
Someone else suggested to marshal the call onto the form thread, by using
the
Invoke, or BeginInvoke function.
The following code is what I do.
If I do like the following, will sub PQ be executed on the MainForm or the
Class GT Thread ?
Thank you.

Public Class MainForm
Private GSession As GT = Nothing
Private GWorkerThread As Threading.Thread = Nothing

Public Sub ConnectMenu_Click
:
' Create a new instance of the ClientSession object and a worker
' thread that will handle the socket I/O
        GSession = New GSession
        GWorkerThread = New Threading.Thread(AddressOf GSession.ThreadMain)


        GSession.ClientForm = Me
        GSession.cb = AddressOf ProcessQuote

        ' Initialize the worker thread and start its execution
        GWorkerThread.Name = "WorkerThread"
        GWorkerThread.Start()
:
end sub

Sub PQ(ByVal Packet As String, ByVal sCaller As String)

Inside the Class Thread:
Public Class GT
    Public ClientForm As MainForm = Nothing
    Public Delegate Sub PQCallBack(ByVal Packet As String, ByVal sCaller As
String)
    Public cb As PQCallBack

    Public Sub ThreadMain()
        Dim d As PQCallBack

        d = cb
d(strBuffer, "CMC")

Show quoteHide quote
"Brian Gideon" <briangid***@yahoo.com> wrote in message
news:1149523419.910250.281280@i39g2000cwa.googlegroups.com...
>
> fniles wrote:
>> Thanks.
>> I just want to make sure.
>> So, even though the code for WriteLine is inside MainForm, but since it
>> is
>> called from ThreadMain, it will run inside the thread, right ?
>>
>
> Yes, that is correct.
>
Author
6 Jun 2006 3:18 PM
Tony Proctor
For future reference, the microsoft.public.vb.general.discussion newsgroup
is not designed for VB.Net. It's for "VB Classic", i.e. VB6 and beyond

        Tony Proctor

Show quoteHide quote
"fniles" <fni***@pfmail.com> wrote in message
news:#bpfq2LiGHA.3780@TK2MSFTNGP03.phx.gbl...
> Thank you all.
> Someone else suggested to marshal the call onto the form thread, by using
> the
> Invoke, or BeginInvoke function.
> The following code is what I do.
> If I do like the following, will sub PQ be executed on the MainForm or the
> Class GT Thread ?
> Thank you.
>
> Public Class MainForm
> Private GSession As GT = Nothing
> Private GWorkerThread As Threading.Thread = Nothing
>
> Public Sub ConnectMenu_Click
>  :
>  ' Create a new instance of the ClientSession object and a worker
>  ' thread that will handle the socket I/O
>         GSession = New GSession
>         GWorkerThread = New Threading.Thread(AddressOf
GSession.ThreadMain)
>
>
>         GSession.ClientForm = Me
>         GSession.cb = AddressOf ProcessQuote
>
>         ' Initialize the worker thread and start its execution
>         GWorkerThread.Name = "WorkerThread"
>         GWorkerThread.Start()
> :
> end sub
>
> Sub PQ(ByVal Packet As String, ByVal sCaller As String)
>
> Inside the Class Thread:
> Public Class GT
>     Public ClientForm As MainForm = Nothing
>     Public Delegate Sub PQCallBack(ByVal Packet As String, ByVal sCaller
As
> String)
>     Public cb As PQCallBack
>
>     Public Sub ThreadMain()
>         Dim d As PQCallBack
>
>         d = cb
>  d(strBuffer, "CMC")
>
> "Brian Gideon" <briangid***@yahoo.com> wrote in message
> news:1149523419.910250.281280@i39g2000cwa.googlegroups.com...
> >
> > fniles wrote:
> >> Thanks.
> >> I just want to make sure.
> >> So, even though the code for WriteLine is inside MainForm, but since it
> >> is
> >> called from ThreadMain, it will run inside the thread, right ?
> >>
> >
> > Yes, that is correct.
> >
>
>