473,320 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Thread Question

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)

Jun 2 '06 #1
6 942
Anything invoked in a Thread should run inside that thread. It's analogous to
launching a separate application.

"fniles" <fn****@pfmail.com> wrote in message
news:uZ**************@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)

Jun 2 '06 #2
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" <se******@mouse-potato.com> wrote in message
news:O8**************@TK2MSFTNGP04.phx.gbl...
Anything invoked in a Thread should run inside that thread. It's
analogous to launching a separate application.

"fniles" <fn****@pfmail.com> wrote in message
news:uZ**************@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)



Jun 5 '06 #3
Unless I'm missing something, it should.

"fniles" <fn****@pfmail.com> wrote in message
news:%2****************@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" <se******@mouse-potato.com> wrote in message
news:O8**************@TK2MSFTNGP04.phx.gbl...
Anything invoked in a Thread should run inside that thread. It's
analogous to launching a separate application.

"fniles" <fn****@pfmail.com> wrote in message
news:uZ**************@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)



Jun 5 '06 #4

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.

Jun 5 '06 #5
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" <br*********@yahoo.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.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.

Jun 5 '06 #6
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

"fniles" <fn****@pfmail.com> wrote in message
news:#b**************@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" <br*********@yahoo.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.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.


Jun 6 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: rnn98 | last post by:
hi, my multithread application, running under solaris box, is crashing eventually. I tried to spot and substitute functions not "thread safe", but I guess my search wasn't good enough. I have put...
5
by: Bill Davidson | last post by:
Hello All: I've got a question about synchronization requiremements in a C# worker thread procedure that, among other things, sinks events from outside sources. I realize the worker thread will...
1
by: Bill Davidson | last post by:
(RESEND: I added a little more code to the sample for clarity) Hello All: I've got a question about synchronization requiremements in a C# worker thread procedure that, among other things,...
2
by: James Lavery | last post by:
Hi everyone, We're developing an application to capture data from several serial ports, store in a database, and (optionally) forward on using FTP. Each serial port is being processed in a...
22
by: Morpheus | last post by:
Hi, I have been coding in Windows for many years so have a mindset to it, so forgive any stupid questions. Is it possible to create a multithread application in C++ that is portable...
6
by: Sergey Poberezovskiy | last post by:
I have the following code in C# that I have trouble converting to VB(2.0): private delegate void openDialog(); private void openWindowsDialog(openDialog open) { Thread thread = new Thread(new...
34
by: Creativ | last post by:
Why does Thread class not support IDisposable? It's creating quite some problem. Namely, it can exhaust the resource and you have not control over it.
19
by: Hapa | last post by:
Does only reading (never writing) of a variable need thread synchronisation? Thanks for help? PS. Anybody knows a Visual C++ news group?
9
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got a routine that builds a table using different queries, different SQL Tables, and adding custom fields. It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the table...
2
by: k3xji | last post by:
Hi all, This will probably be a long question/short answer, sorry, but I have wandered net about the subject and really feel cannot find just enough information.I want to ask my question by...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.