I am trying to debug a deadlock between several threads in a Windows (Metro) Store app written in C++, and it would be helpful to have each thread store it’s ID at various points so I can figure out which thread each of the other block threads is waiting for.
The .NET for Windows Store apps overview says to use Environment::CurrentManagedThreadId in the System namespace to access the thread. I would have thought I could simply write:
int threadId = System::Environment::CurrentManagedThreadId;
but, Visual Studio 2012 complains that “‘System’: is not a class or namespace name”, when I try to compile the cpp file.
Am I missing a header file that defines the System namespace? I don’t see any header files listed in the System.Environment or Environment.CurrentManagedThreadId web pages.
FWIW, the object browser within Visual Studio 2012 shows me the System.Environment object, and the object browser shows that it should have a CurrentManagedThreadId property.
C++/CX does not target .NET. You cannot use the .NET Framework directly from C++/CX code.
You can use the Windows API function
GetCurrentThreadIdto get the current thread identifier.