|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Thread Questionfrom 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) : Code from inside thread:end sub Public Class ClientSession Public ClientForm As MainForm = Nothing Public Sub ThreadMain() : ClientForm.WriteLine(strBuffer)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) > > > 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) >> >> >> > > 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) >>> >>> >>> >> >> > > > fniles wrote:
> Thanks. Yes, that is correct.> 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 ? > 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() : Sub PQ(ByVal Packet As String, ByVal sCaller As String)end sub 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. > 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. > > > >
String wierdness...
Data base insert Error HELP! Adding a row to a table help! Is there a Forms collection? Thread question Converting Code from VBA to VB.NET trying to download VS2005 from MSDN Why doesn't changing the position in a table change the position of the DatGridView that's bound to How to measure bandwidth need by the application Is RegEx a good choice for reading malformed xml? |
|||||||||||||||||||||||