473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

User Control and Threading Help

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!

Feb 28 '06 #1
3 2233
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!

Mar 1 '06 #2
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?

Mar 1 '06 #3
"teillon" <te*****@mountainshadow.com> schrieb
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?

No. All windows, this includes controls, that have a relation to each other
(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

Mar 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jas | last post by:
I have a basic client/server socket situation setup....where the server accepts a connection and then waits for commands. On the client side, I create a socket, connect to the server...then I...
0
by: Duncan Mole | last post by:
Hi, I have created a control which draws a title bar and provides a drop down menu for a Smart Device Application. It seemed to work fine until I came to add an event handler to act on Paint...
1
by: Simon M | last post by:
Hi, I'm not sure where to post this as it's about windows forms, web forms, socket communication and embedded objects. I am developing a smart client which is embedded in a webform. This...
7
by: davetelling | last post by:
I'm a newbie that is still struggling with OOP concepts & how to make things work they way I want. Using Visual C# Express, I have a form in which I added a user control to display a graph, based...
6
by: Joe | last post by:
I've been getting this message at all different times since a few days ago. I understand the message but not why I get it. I don't have any other threads. This happens when closing dialog boxes,...
5
by: lazy | last post by:
Hi, I want to write a script such that it executes 2 mysql queries on the server. But before executing the second query, I would like to return the results of the first query to the user and then...
0
by: Baz | last post by:
Hi, I am new to VB .net (long time VBA programmer) and was trying to integrate a freeware list bar control into a windows mdi child form in VB.net 2005 Express. I think I am doing it right,...
0
by: Baz | last post by:
Hi, I am new to VB .net (long time VBA programmer) and was trying to integrate a freeware list bar control into a windows mdi child form in VB.net 2005 Express. I think I am doing it right,...
1
by: asedt | last post by:
I made this progarm in Visual studio 2005 vith COM Interop, I want to change the program so it does'n turn of excel and let the user control the application insted after the macro have run. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.