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

How to determine the current thread

I would like to know what thread my form is running on in a Managed C++
Windows Form Application

I tried

using namespace System::Diagnostics;
using namespace System::Threading;

and including the code

Debug::WriteLine(Thread::CurrentThread->Name->ToString());

in my form constructor

This compiles but results in a Null Reference exception

Howard Weiss
Nov 17 '05 #1
1 1075
Howard,
I would like to know what thread my form is running on in a Managed C++
Windows Form Application

I tried

using namespace System::Diagnostics;
using namespace System::Threading;

and including the code

Debug::WriteLine(Thread::CurrentThread->Name->ToString());

in my form constructor

This compiles but results in a Null Reference exception


First of all, there's no need to call ToString(), the Name property is
already a string.

Second of all, it's perfectly normal for a thread to have no name (indeed it
probably won't unless you set it yourself). Now, in Win32, one would usually
identify the thread by it's thread id. However, in managed code, you don't
normally would get that since theoretically, managed threads don't need to
map one-to-one to the underlying OS threads (you can still call the Win32
GetCurrentThreadId() api). If all you want to do is distinguish one managed
thread from another, you can use it's hashcode.

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #2

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

Similar topics

17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
4
by: Prehaut Anselme | last post by:
Hi, I need to create a WebRequest with an automatic proxy I have the specification of this porxy (host & port) I ask the user their own login and password, but the proxy tells me that the...
6
by: Arsen V. | last post by:
Hello, I have a localization class that I want to use from either Web or Windows Forms apps. Currently it stores some information in the HttpRuntime.Cache object. I want to be able to determine...
7
by: semedao | last post by:
Hi all, I view many posts about this issue , the connected property does not tell us the current status of the socket. based on couple of suggestions of msdn , and some article here , I try to...
7
by: MyndPhlyp | last post by:
I've been combing through Google trying to find the answer but not luck. I'm using Forms authentication. Determining what Roles the current user is in was the easy part (User.IsInRole). But how...
1
by: My interest | last post by:
Is it possible to determine the remoting settting in runtime from within the host class? Assuming I have a class Bar whose listening URI is tcp://localhost:2345/Bar. This URI is specified in the...
9
by: | last post by:
I am interested in scanning web pages for content of interest, and then auto-classifying that content. I have tables of metadata that I can use for the classification, e.g. : "John P. Jones" "Jane...
2
by: =?Utf-8?B?YWxiZXJ0b3Nvcmlh?= | last post by:
Hi, I'm using Threads, and when I try to do Server.Transfer, I recieved an error. (child object does not exist...) My Code: Dim t As New Thread(AddressOf Hilo) Private Sub Hilo()...
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...
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: 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
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,...

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.