View Single Post
  #5 (permalink)  
Old April 12th, 2007, 02:28 PM
jwebb jwebb is offline
Registered User
 
Join Date: Apr 2007
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I appreciate the analogy to an everyday situation. The idea behind threading is brought out plainly in your diner scenario. At the risk of making myself look too much like a beginner, I have to ask for a bit more help.

The concepts being solid, it's the syntax that gets me. Especially when it comes to delegates. Consider the following elementary problem:

1. A form with a textbox (displaying count) and two buttons (start, kill)
2. If the user clicks on the start button, an infinite loop is commenced say,

dim i as integer
i=1
while i>0
i=i+1
end while

3. Obviously, the user has a long wait in front of them. But let's say that while the programmer wasn't quick-witted enough to avoid the infinite loop, he was code-savvy enough to put the incrementing process on a separate thread. Now we can say that the start button event handler is used to initiate the creation of a secondary thread where the above code will now be processed.

4. The kill button affords the user the opportunity to .abort the loop. Problem solved.

5. But suppose while the variable is incrementing on it's separate thread, we want the counter to update in the textbox (perhaps using the thread sleep command for 3 second pauses)? This necessitates invoking the original thread, which is where I lose track of the syntax.

I believe that if someone can show me the proper syntax for this procedure, I can take it from there.

One more question - is the moving back and forth between threads a time consuming process?

Again thanks for your help.