I don't think it works like that - every user control runs in the same
thread unless you explicitly tell it otherwise.
I've never used threading but you inspired me to have a pop at it.
Here's a demo that just populates a textbox on the main thread, it pops
up a message box -- so you can tell it's running in a separate thread:
'at top of module
Imports System.Threading
' place Button1 and TextBox1 on the form
'place this in Form class
Sub ThreadTest()
'make a new thread for our mySecondThread proc
Dim t As New Thread(New ThreadStart(AddressOf mySecondThread))
t.Start()
For i As Integer = 1 To 20
TextBox1.Text = TextBox1.Text & Now.ToLongTimeString _
& ControlChars.CrLf
TextBox1.Refresh()
'wait a bit
Thread.Sleep(200)
Next i
End Sub
Sub mySecondThread()
MsgBox("oooh")
MsgBox("ahhhh")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
ThreadTest()
End Sub
HTH
teillon wrote:
I'm trying to write a VB.NET utility that performs a looping task--say,
list all files in a directory, over and over again, continuously.
I want to be able to put this logic in a User Control with a text box
for the path to monitor and a list box to display the results.
I want to be able to drop this control numerous times on a parent
project form and have them all run asyncronysly.
I am not a Threading expert, but I was assuming that each User Control
would run in it's own thread.
However, the results I'm getting show differently. If I have two
controls on the form and start one it runs fine, but when I start the
other one, the first one "pauses" until the second is stopped.
I know I need to do some threading here, but am having problems getting
it right. Is there a simple way to wrap the ENTIRE user control class
in it's own thread?
Thanks!