|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Thread questioncalling 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 aworker ' 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 oroutside the thread ????? : Thanks.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. > 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. >> > > 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() : 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 "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. >> > >
String wierdness...
Calling VB.Net classes from VB6 Data base insert Error HELP! Adding a row to a table help! Is there a Forms collection? How to measure bandwidth need by the application Converting Code from VBA to VB.NET Why doesn't changing the position in a table change the position of the DatGridView that's bound to Is RegEx a good choice for reading malformed xml? Ambiguous in the Namespace |
|||||||||||||||||||||||