Home All Groups Group Topic Archive Search About
Author
2 Jun 2006 3:15 PM
fiefie.niles
I am using a thread. Inside the thread there is a sub ThreadMain. I am
calling the thread from the main program MainForm.
Inside the thread, if I am calling a sub (say doProcess) from the
MainForm, does it mean that doProcess is processed inside or outside
the thread ?

Code from MainForm:
Public Class MainForm
Private Session As ClientSession = Nothing
Private WorkerThread 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
        Session = New ClientSession
        WorkerThread = New Threading.Thread(AddressOf
Session.ThreadMain)

        Session.ClientForm = Me

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

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

Public Sub ThreadMain()
:
  ClientForm.doProcess(strBuffer)  --->will this be executed inside or
outside the thread ?????
:

Thanks.

Author
2 Jun 2006 4:22 PM
Robin Mark Tucker
If you call a method from a thread, that process is executed on that thread,
same for your process.  So in your example, the thread will execute the
method on the form, from within the thread - not a good idea.

What you can do is to marshal the call onto the form thread, by using the
Invoke, or BeginInvoke function.    Here is a simple page I found that
explains the basics:

http://abstractvb.com/code.asp?A=1027




<fiefie.ni***@gmail.com> wrote in message
Show quoteHide quote
news:1149261322.510095.76070@g10g2000cwb.googlegroups.com...
>I am using a thread. Inside the thread there is a sub ThreadMain. I am
> calling the thread from the main program MainForm.
> Inside the thread, if I am calling a sub (say doProcess) from the
> MainForm, does it mean that doProcess is processed inside or outside
> the thread ?
>
> Code from MainForm:
> Public Class MainForm
> Private Session As ClientSession = Nothing
> Private WorkerThread 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
>        Session = New ClientSession
>        WorkerThread = New Threading.Thread(AddressOf
> Session.ThreadMain)
>
>        Session.ClientForm = Me
>
>        ' Initialize the worker thread and start its execution
>         WorkerThread.Name = "WorkerThread"
>        WorkerThread.Start()
>
> Code from the thread:
> Public Class ClientSession
>    Public ClientForm As MainForm = Nothing
>
> Public Sub ThreadMain()
> :
>  ClientForm.doProcess(strBuffer)  --->will this be executed inside or
> outside the thread ?????
> :
>
> Thanks.
>
Author
4 Jun 2006 2:54 PM
fniles
Thanks.
Isn't Invoke only for changing a control in the form thread ?
Inside ClientForm.doProcess, I do call Invoke when changing a textbox value
from the form thread.
Do I also have to call doProcess using the invoke method ?

Thanks.

Show quoteHide quote
"Robin Mark Tucker" <robintuckerhome@removehotmail.comremove> wrote in
message news:e5pojp$djj$1$8302bc10@news.demon.co.uk...
> If you call a method from a thread, that process is executed on that
> thread, same for your process.  So in your example, the thread will
> execute the method on the form, from within the thread - not a good idea.
>
> What you can do is to marshal the call onto the form thread, by using the
> Invoke, or BeginInvoke function.    Here is a simple page I found that
> explains the basics:
>
> http://abstractvb.com/code.asp?A=1027
>
>
>
>
> <fiefie.ni***@gmail.com> wrote in message
> news:1149261322.510095.76070@g10g2000cwb.googlegroups.com...
>>I am using a thread. Inside the thread there is a sub ThreadMain. I am
>> calling the thread from the main program MainForm.
>> Inside the thread, if I am calling a sub (say doProcess) from the
>> MainForm, does it mean that doProcess is processed inside or outside
>> the thread ?
>>
>> Code from MainForm:
>> Public Class MainForm
>> Private Session As ClientSession = Nothing
>> Private WorkerThread 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
>>        Session = New ClientSession
>>        WorkerThread = New Threading.Thread(AddressOf
>> Session.ThreadMain)
>>
>>        Session.ClientForm = Me
>>
>>        ' Initialize the worker thread and start its execution
>>         WorkerThread.Name = "WorkerThread"
>>        WorkerThread.Start()
>>
>> Code from the thread:
>> Public Class ClientSession
>>    Public ClientForm As MainForm = Nothing
>>
>> Public Sub ThreadMain()
>> :
>>  ClientForm.doProcess(strBuffer)  --->will this be executed inside or
>> outside the thread ?????
>> :
>>
>> Thanks.
>>
>
>
Author
4 Jun 2006 4:27 PM
fniles
The following code is what I do. Pls let me know if it looks ok to you.
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
"Robin Mark Tucker" <robintuckerhome@removehotmail.comremove> wrote in
message news:e5pojp$djj$1$8302bc10@news.demon.co.uk...
> If you call a method from a thread, that process is executed on that
> thread, same for your process.  So in your example, the thread will
> execute the method on the form, from within the thread - not a good idea.
>
> What you can do is to marshal the call onto the form thread, by using the
> Invoke, or BeginInvoke function.    Here is a simple page I found that
> explains the basics:
>
> http://abstractvb.com/code.asp?A=1027
>
>
>
>
> <fiefie.ni***@gmail.com> wrote in message
> news:1149261322.510095.76070@g10g2000cwb.googlegroups.com...
>>I am using a thread. Inside the thread there is a sub ThreadMain. I am
>> calling the thread from the main program MainForm.
>> Inside the thread, if I am calling a sub (say doProcess) from the
>> MainForm, does it mean that doProcess is processed inside or outside
>> the thread ?
>>
>> Code from MainForm:
>> Public Class MainForm
>> Private Session As ClientSession = Nothing
>> Private WorkerThread 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
>>        Session = New ClientSession
>>        WorkerThread = New Threading.Thread(AddressOf
>> Session.ThreadMain)
>>
>>        Session.ClientForm = Me
>>
>>        ' Initialize the worker thread and start its execution
>>         WorkerThread.Name = "WorkerThread"
>>        WorkerThread.Start()
>>
>> Code from the thread:
>> Public Class ClientSession
>>    Public ClientForm As MainForm = Nothing
>>
>> Public Sub ThreadMain()
>> :
>>  ClientForm.doProcess(strBuffer)  --->will this be executed inside or
>> outside the thread ?????
>> :
>>
>> Thanks.
>>
>
>