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 10 1761
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.Diagnost ics.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]
Darian,
Do it like most people, just set a boolean array for it and set that to true
something like
private threadrunnunnin g(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
You may use Process.Threads property. On the returned collection, use the
ThreadState property on individual elements to filter out running threads
(for ThreadState.Run ning).
Hope this is what you are looking for.
"Darian" <da***********@ lmicorporation. com> wrote in message
news:fa******** *************** **@posting.goog le.com...
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
* Tom Shelton <to*@YOUKNOWTHE DRILLmtogden.co m> 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.Diagnost ics.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/>
In article <2q************ @uni-berlin.de>, Herfried K. Wagner [MVP] wrote: * Tom Shelton <to*@YOUKNOWTHE DRILLmtogden.co m> 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.Diagnost ics.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]
* Tom Shelton <to*@YOUKNOWTHE DRILLmtogden.co m> scripsit: In article <2q************ @uni-berlin.de>, Herfried K. Wagner [MVP] wrote: * Tom Shelton <to*@YOUKNOWTHE DRILLmtogden.co m> 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.Diagnost ics.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/>
In article <2q************ @uni-berlin.de>, Herfried K. Wagner [MVP] wrote: * Tom Shelton <to*@YOUKNOWTHE DRILLmtogden.co m> scripsit: In article <2q************ @uni-berlin.de>, Herfried K. Wagner [MVP] wrote: * Tom Shelton <to*@YOUKNOWTHE DRILLmtogden.co m> 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.Diagnost ics.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.Threadin g;
using System.Diagnost ics;
namespace ConsoleApplicat ion17
{
/// <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.GetCurr entProcess ();
Console.WriteLi ne ("Intitial: " + p.Threads.Count );
Thread[] threads = new Thread[10];
for (int i = 0; i < threads.Length; i++)
{
threads[i] = new Thread (new ThreadStart
(Class1.ThreadF unc));
threads[i].Start ();
}
Thread.Sleep (2000);
Console.WriteLi ne ("============= =============== ===");
p = Process.GetCurr entProcess ();
Console.WriteLi ne ("New: " + p.Threads.Count );
foreach (ProcessThread pthread in p.Threads)
{
Console.WriteLi ne (pthread.Id);
}
}
static void ThreadFunc()
{
Console.WriteLi ne ("Child: " + Class1.GetCurre ntThreadId
());
Thread.Sleep (new TimeSpan (0, 0, 0, 20, 0));
}
[DllImport ("kernel32")]
static extern IntPtr GetCurrentThrea dId ();
}
}
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]
Tom,
* Tom Shelton <to*@YOUKNOWTHE DRILLmtogden.co m> 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.Diagnost ics.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.Threadin g; using System.Diagnost ics;
namespace ConsoleApplicat ion17 { /// <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.GetCurr entProcess ();
Console.WriteLi ne ("Intitial: " + p.Threads.Count ); Thread[] threads = new Thread[10]; for (int i = 0; i < threads.Length; i++) { threads[i] = new Thread (new ThreadStart (Class1.ThreadF unc)); threads[i].Start (); }
Thread.Sleep (2000); Console.WriteLi ne ("============= =============== ===");
p = Process.GetCurr entProcess (); Console.WriteLi ne ("New: " + p.Threads.Count ); foreach (ProcessThread pthread in p.Threads) { Console.WriteLi ne (pthread.Id); } }
static void ThreadFunc() { Console.WriteLi ne ("Child: " + Class1.GetCurre ntThreadId ()); Thread.Sleep (new TimeSpan (0, 0, 0, 20, 0)); }
[DllImport ("kernel32")] static extern IntPtr GetCurrentThrea dId (); } }
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/>
On 08 Sep 2004 01:59:58 +0200, Herfried K. Wagner [MVP] wrote: Tom,
* Tom Shelton <to*@YOUKNOWTHE DRILLmtogden.co m> 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.Diagnost ics.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.Threadin g; using System.Diagnost ics;
namespace ConsoleApplicat ion17 { /// <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.GetCurr entProcess ();
Console.WriteLi ne ("Intitial: " + p.Threads.Count ); Thread[] threads = new Thread[10]; for (int i = 0; i < threads.Length; i++) { threads[i] = new Thread (new ThreadStart (Class1.ThreadF unc)); threads[i].Start (); }
Thread.Sleep (2000); Console.WriteLi ne ("============= =============== ===");
p = Process.GetCurr entProcess (); Console.WriteLi ne ("New: " + p.Threads.Count ); foreach (ProcessThread pthread in p.Threads) { Console.WriteLi ne (pthread.Id); } }
static void ThreadFunc() { Console.WriteLi ne ("Child: " + Class1.GetCurre ntThreadId ()); Thread.Sleep (new TimeSpan (0, 0, 0, 20, 0)); }
[DllImport ("kernel32")] static extern IntPtr GetCurrentThrea dId (); } }
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] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 make my life easier I usually put all the templates in one folder and
the name of the sub-folder is the name of the template.
Instead of updating a file every time would there be a way of listing all
the files in one directory, (../template), and all...
|
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 groups
knows a solution.
I'm using code (roughly like):
using System;
using System.Management;
public class Foo {
|
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 Date.
Thanks.
JBESr
|
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 alive threads my program could
have each time the program runs. I use a number of threads in a simulation
tool.
Many thanks in advance.
Best regards
|
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 top
level of the hierarchy) -- like message posts and their replies. Is
there a built-in way to do this, or a generally accepted simplest way?
My first idea was to create a user control like HierarchicalListing
that contains a Repeater, and...
| |
by: Claude Henchoz |
last post by:
Hi
Is there any way of listing partitions on a (win32) computer without
using WMI?
Cheers, Claude
|
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, localtime, ctime, tmpnam, strtok
http://www.lambdacs.com/cpt/FAQ.html#Q150
However, extra Googling hinted rand() and srand(), also being
unsuitable for multi-threading - opinions? And what is the status of
|
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 reason,
HttpSession.Current.Session.SessionID is blank when accessed inside these
threads, but works fine outside them in the main button click handler.
I've looked at using ParameterizedThreadStart to pass the session ID to the
thread, but this...
|
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 can be one minute or one hour)
the Pretty Listing starts acting weird. For instance, if I start writing
"for...", it changes it to f(o) r" or something like that.
When that starts happening, I can't code at all and have to restart VS.
Sometimes...
|
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,...
|
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...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |