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

Monitoring Multiple Threads

I am starting a number of threads as follows:

For n = 1 To 10
Dim t As New Thread(New ThreadStart(MyProcedure))
t.Name = "Thread " & Trim(Str(n))
t.Start()
Next n

I have a timer that, everytime it fired needs to check that all my threads
are running. I am having difficulties using the t.IsAlive property because
't' is not unique to one thread. I feel I need something like
't.name("Thread1").IsAlive'. In other words, "Is thread "Thread1" still
alive?

How can I get a unique reference to each thread that I can then use?

Thanks

-Jerry
Nov 21 '05 #1
4 1291
What you need is something that holds the reference to each array that you
create. Try a hashtable:

WARNING: The following code is off the top of my head and it is late,..
Might not compile 100% without a bit of tweaking....

Dim threadList as New HashTable
For n = 1 To 10
Dim t As New Thread(New ThreadStart(MyProcedure))
t.Name = "Thread " & Trim(Str(n))
t.Start()
threadList.Add(t.Name, t)

Next n

Now, you should be able to do something like:

Dim isAlive as Boolean

isAlive = DirectCast(threadList.Item("Thread1"), System.Thread).IsAlive


"Jerry Spence1" <je**********@somewhere.com> wrote in message
news:42***********************@ptn-nntp-reader02.plus.net...
I am starting a number of threads as follows:

For n = 1 To 10
Dim t As New Thread(New ThreadStart(MyProcedure))
t.Name = "Thread " & Trim(Str(n))
t.Start()
Next n

I have a timer that, everytime it fired needs to check that all my threads
are running. I am having difficulties using the t.IsAlive property because
't' is not unique to one thread. I feel I need something like
't.name("Thread1").IsAlive'. In other words, "Is thread "Thread1" still
alive?

How can I get a unique reference to each thread that I can then use?

Thanks

-Jerry

Nov 21 '05 #2
Thanks Ray. Actually I tried this with a collection as follows:
Public runningThreads As New Collection

Dim t As New Thread(New ThreadStart(AddressOf MyProcedure))
t.Name = "ReaderThread" & Trim(Str(n))
t.Start()
runningThreads.Add(t)
Then in my Timer:

For Each t In runningThreads
If t.ThreadState = Threading.ThreadState.Stopped Then
Dim t1 As New Thread(New ThreadStart(MyProcedure))
t1.Name = t.Name
runningThreads.Remove(q)
t1.Start()
runningThreads.Add(t1)
End If
Next

However, I am having a few problems with it. What is the difference between
a collection and a hashtable as far as this problem is concerned?

Thanks

-Jerry
"Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message
news:ut*************@TK2MSFTNGP14.phx.gbl...
What you need is something that holds the reference to each array that you
create. Try a hashtable:

WARNING: The following code is off the top of my head and it is late,..
Might not compile 100% without a bit of tweaking....

Dim threadList as New HashTable
For n = 1 To 10
Dim t As New Thread(New ThreadStart(MyProcedure))
t.Name = "Thread " & Trim(Str(n))
t.Start()
threadList.Add(t.Name, t)

Next n

Now, you should be able to do something like:

Dim isAlive as Boolean

isAlive = DirectCast(threadList.Item("Thread1"), System.Thread).IsAlive


"Jerry Spence1" <je**********@somewhere.com> wrote in message
news:42***********************@ptn-nntp-reader02.plus.net...
I am starting a number of threads as follows:

For n = 1 To 10
Dim t As New Thread(New ThreadStart(MyProcedure))
t.Name = "Thread " & Trim(Str(n))
t.Start()
Next n

I have a timer that, everytime it fired needs to check that all my
threads are running. I am having difficulties using the t.IsAlive
property because 't' is not unique to one thread. I feel I need something
like 't.name("Thread1").IsAlive'. In other words, "Is thread "Thread1"
still alive?

How can I get a unique reference to each thread that I can then use?

Thanks

-Jerry


Nov 21 '05 #3
The hashtable just lets you keep a reference to your object (your thread
instance in this case) indexed by another object (the thread name in my
exmaple) It lets you get the reference by the index without having to loop
through all the items to get to the one you want.

I am curious what problems you were having though...

The line you have that removes the thread if it is not running:

runningThreads.Revove(q)

....where are you getting q from?

What 'problems' were you having...

"Jerry Spence1" <je**********@somewhere.com> wrote in message
news:42*********************@ptn-nntp-reader03.plus.net...
Thanks Ray. Actually I tried this with a collection as follows:
Public runningThreads As New Collection

Dim t As New Thread(New ThreadStart(AddressOf MyProcedure))
t.Name = "ReaderThread" & Trim(Str(n))
t.Start()
runningThreads.Add(t)
Then in my Timer:

For Each t In runningThreads
If t.ThreadState = Threading.ThreadState.Stopped Then
Dim t1 As New Thread(New ThreadStart(MyProcedure))
t1.Name = t.Name
runningThreads.Remove(q)
t1.Start()
runningThreads.Add(t1)
End If
Next

However, I am having a few problems with it. What is the difference between a collection and a hashtable as far as this problem is concerned?

Thanks

-Jerry
"Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message
news:ut*************@TK2MSFTNGP14.phx.gbl...
What you need is something that holds the reference to each array that you create. Try a hashtable:

WARNING: The following code is off the top of my head and it is late,..
Might not compile 100% without a bit of tweaking....

Dim threadList as New HashTable
For n = 1 To 10
Dim t As New Thread(New ThreadStart(MyProcedure))
t.Name = "Thread " & Trim(Str(n))
t.Start()
threadList.Add(t.Name, t)

Next n

Now, you should be able to do something like:

Dim isAlive as Boolean

isAlive = DirectCast(threadList.Item("Thread1"), System.Thread).IsAlive


"Jerry Spence1" <je**********@somewhere.com> wrote in message
news:42***********************@ptn-nntp-reader02.plus.net...
I am starting a number of threads as follows:

For n = 1 To 10
Dim t As New Thread(New ThreadStart(MyProcedure))
t.Name = "Thread " & Trim(Str(n))
t.Start()
Next n

I have a timer that, everytime it fired needs to check that all my
threads are running. I am having difficulties using the t.IsAlive
property because 't' is not unique to one thread. I feel I need something like 't.name("Thread1").IsAlive'. In other words, "Is thread "Thread1"
still alive?

How can I get a unique reference to each thread that I can then use?

Thanks

-Jerry



Nov 21 '05 #4
Thanks for that Ray - cheers

-Jerry
"Ray Cassick" <rc******@nospam.enterprocity.com> wrote in message
news:Ou**************@TK2MSFTNGP10.phx.gbl...
The hashtable just lets you keep a reference to your object (your thread
instance in this case) indexed by another object (the thread name in my
exmaple) It lets you get the reference by the index without having to loop
through all the items to get to the one you want.

I am curious what problems you were having though...

The line you have that removes the thread if it is not running:

runningThreads.Revove(q)

...where are you getting q from?

What 'problems' were you having...

"Jerry Spence1" <je**********@somewhere.com> wrote in message
news:42*********************@ptn-nntp-reader03.plus.net...
Thanks Ray. Actually I tried this with a collection as follows:
Public runningThreads As New Collection

Dim t As New Thread(New ThreadStart(AddressOf MyProcedure))
t.Name = "ReaderThread" & Trim(Str(n))
t.Start()
runningThreads.Add(t)
Then in my Timer:

For Each t In runningThreads
If t.ThreadState = Threading.ThreadState.Stopped Then
Dim t1 As New Thread(New ThreadStart(MyProcedure))
t1.Name = t.Name
runningThreads.Remove(q)
t1.Start()
runningThreads.Add(t1)
End If
Next

However, I am having a few problems with it. What is the difference

between
a collection and a hashtable as far as this problem is concerned?

Thanks

-Jerry
"Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message
news:ut*************@TK2MSFTNGP14.phx.gbl...
> What you need is something that holds the reference to each array that you > create. Try a hashtable:
>
> WARNING: The following code is off the top of my head and it is late,..
> Might not compile 100% without a bit of tweaking....
>
> Dim threadList as New HashTable
>
>
> For n = 1 To 10
> Dim t As New Thread(New ThreadStart(MyProcedure))
> t.Name = "Thread " & Trim(Str(n))
> t.Start()
> threadList.Add(t.Name, t)
>
> Next n
>
> Now, you should be able to do something like:
>
> Dim isAlive as Boolean
>
> isAlive = DirectCast(threadList.Item("Thread1"), System.Thread).IsAlive
>
>
>
>
> "Jerry Spence1" <je**********@somewhere.com> wrote in message
> news:42***********************@ptn-nntp-reader02.plus.net...
>>I am starting a number of threads as follows:
>>
>> For n = 1 To 10
>> Dim t As New Thread(New ThreadStart(MyProcedure))
>> t.Name = "Thread " & Trim(Str(n))
>> t.Start()
>> Next n
>>
>> I have a timer that, everytime it fired needs to check that all my
>> threads are running. I am having difficulties using the t.IsAlive
>> property because 't' is not unique to one thread. I feel I need something >> like 't.name("Thread1").IsAlive'. In other words, "Is thread "Thread1"
>> still alive?
>>
>> How can I get a unique reference to each thread that I can then use?
>>
>> Thanks
>>
>> -Jerry
>>
>>
>
>



Nov 21 '05 #5

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

Similar topics

2
by: Peter Kirk | last post by:
Hi I would like some general pointers about monitoring some performance parameters of an application we have written. For example: how many threads it has currently running, how long the threads...
2
by: Tumurbaatar S. | last post by:
ASP.NET QuickStart Tutorial says that: .... ASP.NET maintains a pool of HttpApplication instances over the course of a Web application's lifetime. ASP.NET automatically assigns one of these...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
2
by: Brett | last post by:
What are the advantages/disadvantages of using one process with multiple threads or doing the same task with multiple processes, each having one thread? I see using multiple threads under one...
3
by: ian_jacobsen | last post by:
First let me start by saying that this problem is not consistently reproducible. I have a windows service that creates reports for a group of entities. This service can process multiple groups at...
7
by: =?Utf-8?B?Q2FybG8gRm9saW5p?= | last post by:
Hi, I implemented asynchronous calls to a web resource (using HttpWebRequest) from asp.net 2.0. The request it's made asyncronously (I see that beginGetResponse returns immediately). The number...
35
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from...
4
by: rohit | last post by:
hello, i have designed a desktop search utility in python and a file system monitoring using readdirectorychangesw from win32api but for eg. it has a high cpu utilization (using a 2GHz processor)....
16
by: WATYF | last post by:
Hi there... I have a huge text file that needs to be processed. At the moment, I'm loading it into memory in small chunks (x amount of lines) and processing it that way. I'd like the process to be...
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
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...
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
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...
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.