By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,192 Members | 1,783 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,192 IT Pros & Developers. It's quick & easy.

How to determine the current thread

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.