473,396 Members | 1,789 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,396 software developers and data experts.

Threading / updating textbox question

Hello! And thanks in advance. I have the following code which just
basically creates a set of threads for me (Using svrList as my list of
class instances to thread). Let's call the threads workerthreads.

The worker threads need to update a textbox on Form1 as they progress.

The question is, how do I create the necessary delegates / whatever to
update the textbox in a thread - safe manner?

The classes created in svrList are all instances of serverClass with
data passed to them during creation.

'Seed threadCount to get it started
threadCount = 1
'Okay, keep going while threads still exist
'If ther are no threads, create a new one as long as there are objects
left in svrList
While threadCount <0
If threadList.Count < My.Settings.numThreads And
svrList.Count 0 Then
Dim Server As serverClass = CType(svrList(0),
serverClass)
Dim svrThread As New Thread(AddressOf Server.getInfo)
threadList.Add(svrThread)
svrThread.Start()
svrList.Remove(Server)
threadCount = threadList.Count
End If
Dim iIndex As Integer = 0

For threadIndex = threadList.Count - 1 To 0 Step -1
sThread = CType(threadList(threadIndex), Thread)
If Not sThread.IsAlive Then
threadList.RemoveAt(threadIndex)
End If

Next

'Thread.Sleep(50)

End While

Jan 5 '07 #1
1 1294
I wanted to clarify this a bit. It's fairly easy to do this when the
background thread is a subroutine on the form, using this technique:
http://msdn2.microsoft.com/en-us/lib...28(vs.80).aspx

But how do I call the setText routine when the background thread is in
a seperate class?

Bmack500 wrote:
Hello! And thanks in advance. I have the following code which just
basically creates a set of threads for me (Using svrList as my list of
class instances to thread). Let's call the threads workerthreads.

The worker threads need to update a textbox on Form1 as they progress.

The question is, how do I create the necessary delegates / whatever to
update the textbox in a thread - safe manner?

The classes created in svrList are all instances of serverClass with
data passed to them during creation.

'Seed threadCount to get it started
threadCount = 1
'Okay, keep going while threads still exist
'If ther are no threads, create a new one as long as there are objects
left in svrList
While threadCount <0
If threadList.Count < My.Settings.numThreads And
svrList.Count 0 Then
Dim Server As serverClass = CType(svrList(0),
serverClass)
Dim svrThread As New Thread(AddressOf Server.getInfo)
threadList.Add(svrThread)
svrThread.Start()
svrList.Remove(Server)
threadCount = threadList.Count
End If
Dim iIndex As Integer = 0

For threadIndex = threadList.Count - 1 To 0 Step -1
sThread = CType(threadList(threadIndex), Thread)
If Not sThread.IsAlive Then
threadList.RemoveAt(threadIndex)
End If

Next

'Thread.Sleep(50)

End While
Jan 8 '07 #2

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

Similar topics

8
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd...
8
by: Yatharth | last post by:
Hi, I m new to threading and i have successfully runed threading but i could display value on my web page ,but its working in code behind when i see it through debugger,plzzzzzzz help me here...
4
by: Darrel | last post by:
I'm creating a table that contains multiple records pulled out of the database. I'm building the table myself and passing it to the page since the table needs to be fairly customized (ie, a...
0
by: cwbp17 | last post by:
I'm having trouble updating individual datagrid cells. Have two tables car_master (columns include Car_ID, YEAR,VEHICLE) and car_detail (columns include Car_ID,PRICE,MILEAGE,and BODY);both tables...
10
by: sqlboy2000 | last post by:
Hello all, I have something very simple going on here and I'm scratching my head as to what the problem is. There are 4 items in my project, 2 webforms, a user control, and a module: ...
4
by: Roger | last post by:
I have a function that is currently wrapped up in a Class so I can pass a variable to it. This function is going to be threaded out and I would like the class function to be able to update a...
0
by: Joergen Bech | last post by:
Source: ------------ http://home1.inet.tele.dk/jbech/binaries/threadingtest.zip (25K) Scenario: --------------- Main form with two listboxes, a textbox, a button, and a trackbar. Clicking...
2
by: Chris Ashley | last post by:
Hi, I'm overriding WndProc to process some custom messages like so: protected override void WndProc(ref Message m) { if (m.Msg == ImageFileMsg.MSG_IF_NEW_DATA) { ProcessNewDataMessage(m);
2
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi All! I am with a situation where I am not getting the right updating to the form's fields. The situation is the following one: I have one combobox and one textbox. I am using the...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.