Similar to multithreading?

M.C
08-31-2003, 11:28 PM
All a thread is, is a code string running on it's own. So, if you have a VB program that starts a form from an array then that form runs on it's own as long as there is something that causes that form code to take action such as a socket recieving data from a host.

Look at it this way. If you used one form with a 100 sockets on that form each socket act on it's own. But the code to handle this is quite complex and it will bogle up the application. So, if you use multiple forms with only two sockets on each then the whole VB applcication runs much better.

The end results of using multiple forms is very much the same as multi-threading as in Java or C++.



Quoted from a different forum

Is this true?

DeX
09-01-2003, 04:35 AM
That doesn't sound right to me. No matter how many forms vb has it will always run with a single thread. Which means that the code from each form will always run syncronously. When an event occurs on one form, VB will wait until the current form has finished processing and then move onto the form which was waiting to be called.

If you want real multi threading then I suggest you look at this:
http://planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=26900

Thinker
09-01-2003, 09:15 AM
That is wrong and so is DeX. VB is Apartment threaded. It can run
many threads in its one MTA (multi-threaded apartment) and can create
as many STAs (single-threaded apartments) as it needs. Because all
threads in the apartment rely on TLS (thread local storage), they have
what is called thread-affinity. Because of this, they must be serialized
so that they can't step all over each other. This means each thread
runs in turn and only when a sub call (or something else that makes the
thread give up its timeslice like DoEvents) is completed can context
switch to another thread. This is why using DoEvents inside of tight
loops allows the system to do other things in your app (like refresh the
screen). This is also why DoEvents can allow a sub to become reentrant
(it can be executed a second time before the first time completes).
There is no simple way to make the threads in a single instance of VB
behave asynchronously (although with a timer and careful use of
DoEvents and making sure subs are protected from reentrancy, you can
simulate it).

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum