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

Getting current thread ID

Ive a static logging routine that's called by all my objects in the
application.
Ive several threads running in my application and Id like the log file to
show the thread ID so I can trace a single thread if I need to.
Ive had a look through system.threading.thread.currentthread
methods/properties but nothing immediately strikes me, how can I obtain a
value for the ID or similar?

thanks
Claire
Nov 17 '05 #1
5 50116
Claire wrote:
Ive a static logging routine that's called by all my objects in the
application.
Ive several threads running in my application and Id like the log file to
show the thread ID so I can trace a single thread if I need to.
Ive had a look through system.threading.thread.currentthread
methods/properties but nothing immediately strikes me, how can I obtain a
value for the ID or similar?

thanks
Claire

i wonder if it is:

system.threading.thread.currentthread.GetDomainID( )
Nov 17 '05 #2
Claire wrote:
Ive a static logging routine that's called by all my objects in the
application.
Ive several threads running in my application and Id like the log file to
show the thread ID so I can trace a single thread if I need to.
Ive had a look through system.threading.thread.currentthread
methods/properties but nothing immediately strikes me, how can I obtain a
value for the ID or similar?

thanks
Claire


i'v done this like that (plus an identation...)

public static void write(string textToAdd, int pm)
{
int indent;

if (!threads.ContainsKey(Thread.CurrentThread))
{
threads.Add(Thread.CurrentThread, 0);
indent = 0;
}
else
{
indent = (int)threads[Thread.CurrentThread];
}

// séparation des threads
if (lastThread != Thread.CurrentThread)

swFromFile.WriteLine("---------------------------------------------------------------------------------------
"+Thread.CurrentThread.Name);

// date
swFromFile.Write(DateTime.Now.ToLongTimeString()+" ");

// indentation
if (pm == -1)
indent--;
for (int i=0; i<indent; i++)
{
swFromFile.Write("\t");
}

if (pm == -1)
indent++;
threads[Thread.CurrentThread] = indent+pm;
// texte
swFromFile.WriteLine(textToAdd);
swFromFile.Flush();

lastThread = Thread.CurrentThread;
}
Nov 17 '05 #3
i wonder if it is:

system.threading.thread.currentthread.GetDomainID( )


Nope, don't think so. That just keeps returning "1" to me
;o(
Nov 17 '05 #4
Thanks for your help Herbert,
I believe it's as follows but,anyone, please correct me if I'm wrong.
int id = System.AppDomain.GetCurrentThreadId();
Nov 17 '05 #5
Thanks z
I tested the two and they both returned the same value, so I'll stick with
dot nets implementation.
Nov 17 '05 #6

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

Similar topics

0
by: Karthey | last post by:
Getting "Could not instantiate ActiveX control because the current thread is not in a single-threaded apartment. " error while using AxMSComLib control. I am working on a Web Application. My...
2
by: Hayk | last post by:
Hello, Does anyone know how to get the current thread's ID in .Net (e.g., for logging purposes)? The Thread class doesn't have thread Id member. There is the Process.Threads property, which...
1
by: Manu | last post by:
I have created a new culture : Dim objCulture As New CultureInfo("he") //hebrew When I tried to assign it to the current thread. Thread.CurrentThread.CurrentCulture = objCulture...
5
by: Mike | last post by:
Hi, How I can get access to current thread. I want to pause it for some seconds. MyThread.Sleep(2000) Thanks
13
by: Steve Enzer | last post by:
How can I get the login name of the user currently logged into Windows as a string? Thanks, Steve Enzer
1
by: Joachim | last post by:
How do I get the current thread ID in C# 2.0? I know there is a deprecated one, but I can't find it. Also, is there another, not deprecated way, of finding the thread id?
15
by: nelsonbrodyk | last post by:
Hey All, Just curious, does anyone know if there is a way to check if the current executing thread is the main WPF GUI thread? I want to have it so that a non-threaded remoting call will fail if...
2
by: tamirmalas | last post by:
Hi, iam trying to set a culture info different than the current culture info on the system, the code compiles fine, but nothing happens, and the system culture is the one used for the program. ...
1
by: bandy | last post by:
Hi there, I am quite confusing in getting page number for pagination links. See what I am doing:I have a ShowDetails.php page on which I have created page links in for loop. Onclick of every...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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,...

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.