|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
User Control and Threading Helplist 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! 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: Show quoteHide quote > 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! > Any experts out there?
Is there no way to "simply" inherit the user control from the Thread class and have it instantiate on the form in it's own thread? "teillon" <teil***@mountainshadow.com> schrieb No. All windows, this includes controls, that have a relation to each other > Any experts out there? > > Is there no way to "simply" inherit the user control from the Thread > class and have it instantiate on the form in it's own thread? (parent/child/owner), must be created in the same thread. Controls don't run in threads. Code runs in threads. You can start a new thread from each Usercontrol. If the thread is to update the Usercontrol, call the control's Invoke or BeginInvoke method. Armin
DataBindings Help
How to retreive deepest XPath value from XML using VB.NET Multiple sdi forms SOAP Client Avoiding & when adding a JavaScript event handler using Attributes.Add() Converting c# to vb.net Frameworks and Check/Install select query changing bound controls data Threading - Object reference not set to an instance of an object VB.Net and SQL Server Developer |
|||||||||||||||||||||||