This site has been so helpful in the past for me over 8 years. I am self taught .net, and have used it primarily with SolidWorks API since 2003. Thread for me is simply threads, and delegates. I run threads in order to crunch data. It keep the main form thread alive while crunching the info. Many times the threads have to send stuff back to the main threaded form. In order to do this without cross thread violations, we need to use delegates. My technique for sending info into a thread, and having the thread call back is rather simple. If I need to create lets say 100 threads. I will use a thread in order to do that. The thread that creates the 100 threads will sleep, only to awake and see if all threads have died. When all threads have died, the main thread cruches and then dies. The main form thread never stalls out, and gets tickled from all sides by all threads from a delegates sub. Here is the code I wrote to explain the most on these topics. Things to note are as follows: Each thread can create its node without limitations. The main thread relys on all threads being done creation. Then the assumtion is made that all thread nodes exist. This can only be true because all threads are not alive. So the main thread changes the display name of each treenode, and then dies itself. The threads and delegates take object arrays, so you can pack them full of anything, both in and out of the thread. The form is very much alive through the whole process. If only a form could speak, because this one is far from a deep sleep. Cheers, Sean P (Sldprt[ItsAboutTime])
Imports System.Threading
Public Class Form1
Dim t1 As Thread
Dim t2 As Thread()
Dim c As Collection
Dim treeview As TreeView
Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tMain()
End Sub
Sub tMain()
c = New Collection
treeview = New TreeView
Me.Controls.Add(treeview)
treeview.Size = New Size(200, 400)
treeview.Location = New Point(10, 6)
treeview.Visible = True
c.Add(100, "StartData")
t1 = New Thread(AddressOf MainThreading)
t1.Start(New Object() {c})
End Sub
Sub MainThreading(ByVal args As Object)
With CType(args(0), Collection)
ReDim t2(.Item("StartData"))
Dim i As Integer
For i = 0 To UBound(t2)
.Add(i, "ThreadKey" & i)