473,811 Members | 3,314 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2262
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.Threadin g

' 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(Add ressOf mySecondThread) )
t.Start()
For i As Integer = 1 To 20
TextBox1.Text = TextBox1.Text & Now.ToLongTimeS tring _
& ControlChars.Cr Lf
TextBox1.Refres h()
'wait a bit
Thread.Sleep(20 0)
Next i
End Sub
Sub mySecondThread( )
MsgBox("oooh")
MsgBox("ahhhh")
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) 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*****@mounta inshadow.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
9458
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 pass the socket to a class which just reads from the socket (in a thread). class Reader(Thread): def run(self): while 1:
0
1910
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 messages in the form which has drawn the control. Evidently, the control is consuming all of these messages. How can I pass them back/on? I have a reference to the owner form but calling Refresh() via this reference isn't helping. Help! Do I need to...
1
1532
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 client software communicates with a third party windows service over sockets. However I have a weird exception being raised in the AppDomain that I can't handle. When I finish the socket communication (all asyncronous) I popup a modal winform, which...
7
5400
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 upon data received via the serial port. If I run the serial port in the main form code, I can get data and, using public properties of the user control, transfer the data to be shown on the graph. However, I am trying to add a feature that will...
6
32249
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, doing a drag and drop and a few other things which I don't remember right now. It only happens while I'm running within the IDE and only seems to be on my computer. We've tested the same thing on other machines running VS.2005 and there is no...
5
1287
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 do my second query or second query can go on asynchronously Something like <?php $q1=...
0
788
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, obviously I'm not though!... Details of the control itself and links to the dll's required are on; =http://www.vbaccelerator.com/home/NET/Code/Controls/ListBar/VSNet_Style_List_Bar/article.asp
0
899
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, obviously I'm not though!... Details of the control itself and links to the dll's required are on; =http://www.vbaccelerator.com/home/NET/Code/Controls/ListBar/VSNet_Sty...
1
1680
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. Dim oExcel As Excel.Application Dim oBook As Excel.Workbook Dim oBooks As Excel.Workbooks 'Start excel oExcel = CreateObject("Excel.Application") oExcel.Visible = True
0
9731
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10405
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4342
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3871
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.