Click here to Skip to main content
15,907,392 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Why does .ThreadState.ToString Behave This Way? Pin
AlphaDeltaTheta4-Jul-13 21:19
AlphaDeltaTheta4-Jul-13 21:19 
GeneralRe: Why does .ThreadState.ToString Behave This Way? Pin
treddie4-Jul-13 21:37
treddie4-Jul-13 21:37 
AnswerRe: Why does .ThreadState.ToString Behave This Way? Pin
AlphaDeltaTheta4-Jul-13 21:49
AlphaDeltaTheta4-Jul-13 21:49 
GeneralRe: Why does .ThreadState.ToString Behave This Way? Pin
treddie4-Jul-13 23:22
treddie4-Jul-13 23:22 
JokeRe: Why does .ThreadState.ToString Behave This Way? Pin
Tim Carmichael5-Jul-13 2:42
Tim Carmichael5-Jul-13 2:42 
GeneralRe: Why does .ThreadState.ToString Behave This Way? Pin
Dave Kreskowiak5-Jul-13 3:57
mveDave Kreskowiak5-Jul-13 3:57 
GeneralRe: Why does .ThreadState.ToString Behave This Way? Pin
treddie5-Jul-13 11:38
treddie5-Jul-13 11:38 
GeneralRe: Why does .ThreadState.ToString Behave This Way? Pin
Ron Beyer5-Jul-13 12:20
professionalRon Beyer5-Jul-13 12:20 
First, a little about threading...

Threads are just units of work that are broken up to be run on a processor. There cannot be any more truly asynchronous threads running than there are physical processor cores.

The system has a scheduler which operates in a time cycle, lets call this cycle length "N". In N time, it has to execute all the threads that are available to be run (threads in other states are not scheduled). Each thread is given a time slice, "Y" in which to execute before the processor context switches to another thread. Any unused time is given to the system process which is just a simple loop (processors always have to be doing something). Unless a thread yields (Thread.Yield or Thread.Sleep), it will process for its entire Y period. Processes that do this are using the most processor resources and you can watch the task manager increase in percent usage when this happens.

So, getting back to your comments:

1) Suspending a thread is simply putting its state in the SleepWaitJoin.
2) The "exact" moment that the thread is (I believe) dependent on what the thread is currently doing. If the threads are in the scheduler but have not been run, then I think they are removed from the scheduler. If the thread is running then the scheduler has to wait until the time period expires or the thread yields to place it in the SleepWaitJoin state. So yes, another iteration can "slip" through while this process happens.
3) Queries happen at exactly the same moment according to the threads, this is because the thread executing the query is reading data in a thread that is suspended (one thread is running at a time). This doesn't mean however that you will get the results at the same time, again the thread could yield while reading data and you will get results at different thread times.
4) Again, the results may be different depending on how and when the scheduler interrupts the thread. Even your main thread is a thread, and its scheduled like all the rest of them.

What you are really trying to do is synchronize data between threads, (Thread 1 to main thread and Thread 2 to main thread). You should not rely on when a thread suspends to do this, you need to implement your own synchronization. Luckily there are things like Mutex's, AutoResetEvent, etc that you can use cross-thread to make one thread wait on your main thread to say "go ahead, continue".
GeneralRe: Why does .ThreadState.ToString Behave This Way? Pin
treddie5-Jul-13 19:34
treddie5-Jul-13 19:34 
GeneralRe: Why does .ThreadState.ToString Behave This Way? Pin
Dave Kreskowiak6-Jul-13 4:11
mveDave Kreskowiak6-Jul-13 4:11 
QuestionModules not initializing Pin
treddie4-Jul-13 8:09
treddie4-Jul-13 8:09 
AnswerRe: Modules not initializing Pin
Eddy Vluggen4-Jul-13 9:21
professionalEddy Vluggen4-Jul-13 9:21 
GeneralRe: Modules not initializing Pin
treddie4-Jul-13 10:47
treddie4-Jul-13 10:47 
Questionexcel conditional formatting - or excel control Pin
Member 46241693-Jul-13 4:32
Member 46241693-Jul-13 4:32 
AnswerRe: excel conditional formatting - or excel control Pin
Eddy Vluggen4-Jul-13 5:02
professionalEddy Vluggen4-Jul-13 5:02 
Questionvb.net tree view Pin
walsh273-Jul-13 2:52
walsh273-Jul-13 2:52 
AnswerRe: vb.net tree view Pin
Eddy Vluggen4-Jul-13 3:16
professionalEddy Vluggen4-Jul-13 3:16 
QuestionWebcam Capture and print A5 Paper, Codes (Two Cameras) Pin
Uğur Şirin1-Jul-13 22:57
Uğur Şirin1-Jul-13 22:57 
AnswerRe: Webcam Capture and print A5 Paper, Codes (Two Cameras) Pin
Eddy Vluggen2-Jul-13 0:32
professionalEddy Vluggen2-Jul-13 0:32 
Questionvb6 to vb.net Pin
Smith00530-Jun-13 19:13
Smith00530-Jun-13 19:13 
AnswerRe: vb6 to vb.net Pin
Dave Kreskowiak1-Jul-13 2:21
mveDave Kreskowiak1-Jul-13 2:21 
QuestionHow to get address of a function or method Pin
treddie30-Jun-13 11:05
treddie30-Jun-13 11:05 
AnswerRe: How to get address of a function or method Pin
TnTinMn30-Jun-13 16:46
TnTinMn30-Jun-13 16:46 
GeneralRe: How to get address of a function or method Pin
treddie1-Jul-13 12:17
treddie1-Jul-13 12:17 
GeneralRe: How to get address of a function or method Pin
TnTinMn1-Jul-13 14:28
TnTinMn1-Jul-13 14:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.