472,796 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Listing of available threads

Is there a way to find all the thread names that are running in a
project?

For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and
T5 are running...I want to be able to know that T2, T4 and T5 are
already running.

Thanks,
Darian
Nov 21 '05 #1
10 1673
On 7 Sep 2004 06:42:59 -0700, Darian wrote:
Is there a way to find all the thread names that are running in a
project?

For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and
T5 are running...I want to be able to know that T2, T4 and T5 are
already running.

Thanks,
Darian


You can use the System.Diagnostics.Process class's Threads member to access
your process threads - You won't be able to get the name from there
though...

--
Tom Shelton [MVP]
Nov 21 '05 #2
Darian,

Do it like most people, just set a boolean array for it and set that to true
something like
private threadrunnunning(5) as boolean

threadrunning(1) = true
if threadrunning(1) = true then

That gives you in my opinion real much more performance than checking it
with any other method.

Just my thought,

Cor

"Darian"
Is there a way to find all the thread names that are running in a
project?

For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and
T5 are running...I want to be able to know that T2, T4 and T5 are
already running.

Thanks,
Darian

Nov 21 '05 #3
You may use Process.Threads property. On the returned collection, use the
ThreadState property on individual elements to filter out running threads
(for ThreadState.Running).

Hope this is what you are looking for.

"Darian" <da***********@lmicorporation.com> wrote in message
news:fa*************************@posting.google.co m...
Is there a way to find all the thread names that are running in a
project?

For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and
T5 are running...I want to be able to know that T2, T4 and T5 are
already running.

Thanks,
Darian
Nov 21 '05 #4
* Tom Shelton <to*@YOUKNOWTHEDRILLmtogden.com> scripsit:
Is there a way to find all the thread names that are running in a
project?

For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and
T5 are running...I want to be able to know that T2, T4 and T5 are
already running.


You can use the System.Diagnostics.Process class's Threads member to access
your process threads - You won't be able to get the name from there
though...


This property will give you the number of unmanaged threads, not the
managed threads. So there might be some differences in the results.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5
In article <2q************@uni-berlin.de>, Herfried K. Wagner [MVP] wrote:
* Tom Shelton <to*@YOUKNOWTHEDRILLmtogden.com> scripsit:
Is there a way to find all the thread names that are running in a
project?

For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and
T5 are running...I want to be able to know that T2, T4 and T5 are
already running.


You can use the System.Diagnostics.Process class's Threads member to access
your process threads - You won't be able to get the name from there
though...


This property will give you the number of unmanaged threads, not the
managed threads. So there might be some differences in the results.


Really... I don't see that in the docs. Are you sure about this? I
guess you learn something new every day :)

--
Tom Shelton [MVP]
Nov 21 '05 #6
* Tom Shelton <to*@YOUKNOWTHEDRILLmtogden.com> scripsit:
In article <2q************@uni-berlin.de>, Herfried K. Wagner [MVP] wrote:
* Tom Shelton <to*@YOUKNOWTHEDRILLmtogden.com> scripsit:
Is there a way to find all the thread names that are running in a
project?

For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and
T5 are running...I want to be able to know that T2, T4 and T5 are
already running.

You can use the System.Diagnostics.Process class's Threads member to access
your process threads - You won't be able to get the name from there
though...


This property will give you the number of unmanaged threads, not the
managed threads. So there might be some differences in the results.


Really... I don't see that in the docs. Are you sure about this? I
guess you learn something new every day :)


I never checked it, but I assume that this can be the case ("operating
system threads"):

"
An array of type 'ProcessThread' representing the operating system threads
currently running in the associated process.
"

When starting a new thread using PInvoke inside your .NET application,
then this thread would be listed in 'Threads', but it would not be a
managed thread. If you are using 3rd party components, another
component may start an unmanaged thread.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #7
In article <2q************@uni-berlin.de>, Herfried K. Wagner [MVP] wrote:
* Tom Shelton <to*@YOUKNOWTHEDRILLmtogden.com> scripsit:
In article <2q************@uni-berlin.de>, Herfried K. Wagner [MVP] wrote:
* Tom Shelton <to*@YOUKNOWTHEDRILLmtogden.com> scripsit:
> Is there a way to find all the thread names that are running in a
> project?
>
> For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and
> T5 are running...I want to be able to know that T2, T4 and T5 are
> already running.

You can use the System.Diagnostics.Process class's Threads member to access
your process threads - You won't be able to get the name from there
though...

This property will give you the number of unmanaged threads, not the
managed threads. So there might be some differences in the results.


Really... I don't see that in the docs. Are you sure about this? I
guess you learn something new every day :)


I never checked it, but I assume that this can be the case ("operating
system threads"):

"
An array of type 'ProcessThread' representing the operating system threads
currently running in the associated process.
"

When starting a new thread using PInvoke inside your .NET application,
then this thread would be listed in 'Threads', but it would not be a
managed thread. If you are using 3rd party components, another
component may start an unmanaged thread.


I just little test of this... Just to find out. Here is the C# code:

using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;

namespace ConsoleApplication17
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Process p = Process.GetCurrentProcess ();

Console.WriteLine ("Intitial: " + p.Threads.Count);
Thread[] threads = new Thread[10];
for (int i = 0; i < threads.Length; i++)
{
threads[i] = new Thread (new ThreadStart
(Class1.ThreadFunc));
threads[i].Start ();
}
Thread.Sleep (2000);
Console.WriteLine ("===============================");

p = Process.GetCurrentProcess ();
Console.WriteLine ("New: " + p.Threads.Count);
foreach (ProcessThread pthread in p.Threads)
{
Console.WriteLine (pthread.Id);
}
}

static void ThreadFunc()
{
Console.WriteLine ("Child: " + Class1.GetCurrentThreadId
());
Thread.Sleep (new TimeSpan (0, 0, 0, 20, 0));
}

[DllImport ("kernel32")]
static extern IntPtr GetCurrentThreadId ();
}
}

It does indeed include the managed threads... Though, I did find out
that it doen't update dyanmically. The process instance is a snapshot
of the current state of the application, so if threads are started
after you get the instance, then the will not show up in the Threads
collection.

--
Tom Shelton [MVP]
Nov 21 '05 #8
Tom,

* Tom Shelton <to*@YOUKNOWTHEDRILLmtogden.com> scripsit:
>> Is there a way to find all the thread names that are running in a
>> project?
>>
>> For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and
>> T5 are running...I want to be able to know that T2, T4 and T5 are
>> already running.
>
> You can use the System.Diagnostics.Process class's Threads member to access
> your process threads - You won't be able to get the name from there
> though...

This property will give you the number of unmanaged threads, not the
managed threads. So there might be some differences in the results.
Really... I don't see that in the docs. Are you sure about this? I
guess you learn something new every day :)


I never checked it, but I assume that this can be the case ("operating
system threads"):

"
An array of type 'ProcessThread' representing the operating system threads
currently running in the associated process.
"

When starting a new thread using PInvoke inside your .NET application,
then this thread would be listed in 'Threads', but it would not be a
managed thread. If you are using 3rd party components, another
component may start an unmanaged thread.


I just little test of this... Just to find out. Here is the C# code:

using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;

namespace ConsoleApplication17
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Process p = Process.GetCurrentProcess ();

Console.WriteLine ("Intitial: " + p.Threads.Count);
Thread[] threads = new Thread[10];
for (int i = 0; i < threads.Length; i++)
{
threads[i] = new Thread (new ThreadStart
(Class1.ThreadFunc));
threads[i].Start ();
}
Thread.Sleep (2000);
Console.WriteLine ("===============================");

p = Process.GetCurrentProcess ();
Console.WriteLine ("New: " + p.Threads.Count);
foreach (ProcessThread pthread in p.Threads)
{
Console.WriteLine (pthread.Id);
}
}

static void ThreadFunc()
{
Console.WriteLine ("Child: " + Class1.GetCurrentThreadId
());
Thread.Sleep (new TimeSpan (0, 0, 0, 20, 0));
}

[DllImport ("kernel32")]
static extern IntPtr GetCurrentThreadId ();
}
}

It does indeed include the managed threads... Though, I did find out
that it doen't update dyanmically. The process instance is a snapshot
of the current state of the application, so if threads are started
after you get the instance, then the will not show up in the Threads
collection.


Thanks for investigating. I agree that managed threads are listed in
'Threads', but there is neither a guarantee that all threads listed in
'Threads' have been started in your code (that means, that they are
"managed" threads), nor is, as you say, 'Threads' an active snapshot of
the threads belonging to the process.

Consequently I would set up my own datastructure and keep references to
the threads that are alive there.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #9
On 08 Sep 2004 01:59:58 +0200, Herfried K. Wagner [MVP] wrote:
Tom,

* Tom Shelton <to*@YOUKNOWTHEDRILLmtogden.com> scripsit:
>>> Is there a way to find all the thread names that are running in a
>>> project?
>>>
>>> For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and
>>> T5 are running...I want to be able to know that T2, T4 and T5 are
>>> already running.
>>
>> You can use the System.Diagnostics.Process class's Threads member to access
>> your process threads - You won't be able to get the name from there
>> though...
>
> This property will give you the number of unmanaged threads, not the
> managed threads. So there might be some differences in the results.
>

Really... I don't see that in the docs. Are you sure about this? I
guess you learn something new every day :)

I never checked it, but I assume that this can be the case ("operating
system threads"):

"
An array of type 'ProcessThread' representing the operating system threads
currently running in the associated process.
"

When starting a new thread using PInvoke inside your .NET application,
then this thread would be listed in 'Threads', but it would not be a
managed thread. If you are using 3rd party components, another
component may start an unmanaged thread.


I just little test of this... Just to find out. Here is the C# code:

using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;

namespace ConsoleApplication17
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Process p = Process.GetCurrentProcess ();

Console.WriteLine ("Intitial: " + p.Threads.Count);
Thread[] threads = new Thread[10];
for (int i = 0; i < threads.Length; i++)
{
threads[i] = new Thread (new ThreadStart
(Class1.ThreadFunc));
threads[i].Start ();
}
Thread.Sleep (2000);
Console.WriteLine ("===============================");

p = Process.GetCurrentProcess ();
Console.WriteLine ("New: " + p.Threads.Count);
foreach (ProcessThread pthread in p.Threads)
{
Console.WriteLine (pthread.Id);
}
}

static void ThreadFunc()
{
Console.WriteLine ("Child: " + Class1.GetCurrentThreadId
());
Thread.Sleep (new TimeSpan (0, 0, 0, 20, 0));
}

[DllImport ("kernel32")]
static extern IntPtr GetCurrentThreadId ();
}
}

It does indeed include the managed threads... Though, I did find out
that it doen't update dyanmically. The process instance is a snapshot
of the current state of the application, so if threads are started
after you get the instance, then the will not show up in the Threads
collection.


Thanks for investigating. I agree that managed threads are listed in
'Threads', but there is neither a guarantee that all threads listed in
'Threads' have been started in your code (that means, that they are
"managed" threads), nor is, as you say, 'Threads' an active snapshot of
the threads belonging to the process.

Consequently I would set up my own datastructure and keep references to
the threads that are alive there.


I agree... I would probably use an arraylist or array (depending) to
actually keep a reference to the thread. It was just something that struck
me when I first answered.

--
Tom Shelton [MVP]
Nov 21 '05 #10
Darian,
In addition to the other comments.

Is there a special relationship between your name of the thread & the
thread?

If there is I would store each thread instance in its own variable.

Dim T1, T2, T3, T4, T5 As Thread

When I created the thread I would set the above thread variable, when I
terminated the thread I would clear the above variable.

If there is no special relationship, I would probably use a HashTable.

Of course this assumes you know when the threads start & stop.

Hope this helps
Jay

"Darian" <da***********@lmicorporation.com> wrote in message
news:fa*************************@posting.google.co m...
Is there a way to find all the thread names that are running in a
project?

For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and
T5 are running...I want to be able to know that T2, T4 and T5 are
already running.

Thanks,
Darian

Nov 21 '05 #11

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

Similar topics

1
by: Sims | last post by:
Hi, I have a few different templates that I want to list so my clients can see different styles that are available. So I want to offer them a drop down menu listing all the styles. But to...
0
by: Helge Jensen | last post by:
Having posted in microsoft.public.dotnet.framework.sdk and microsoft.public.dotnet.framework.wmi without receiving any response, I posthere on the off-chance that someone who isn't following those...
4
by: jbesr1230 | last post by:
Hello, How would I print out a listing of the queries that are in a database? I would like to have a spreadsheet style listing with the columns of: Query Name, Description, Modified Date, Created...
5
by: Kovan Akrei | last post by:
Hi, I wonder if it is possible to get hold of avaiable memory (only RAM) on a machine through .Net class library? I do not want to call windws API. I would like to use this to decide how many...
3
by: Bennett Haselton | last post by:
I want to display a hierarchical listing of items from a database table, where, say, each row in the table has an "ID" field and a "parent_id" field giving the ID of its parent (NULL if it's at the...
11
by: Claude Henchoz | last post by:
Hi Is there any way of listing partitions on a (win32) computer without using WMI? Cheers, Claude
2
by: Juuso Hukkanen | last post by:
I need a list of multithreading unsafe C (C99) functions/features. comp.programming.threads provided an initial list of C:ish functions, with following ANSI C functions: asctime, gmtime,...
0
by: Ben Fidge | last post by:
Hi I've got some ASP.NET code that spins off a couple of worker threads during a button click event. These threads call a series of functions that log their activity to a text file. For some...
3
by: Johnny Jörgensen | last post by:
I've got a serious problem. I've got Visual Studio 2005 installed, and of course I'm using the Pretty Listing formatting function. When I start up VS, everything is fine, but after a while (which...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.