.NET Core 1.0 equivalent for System.Threading.Thread.CurrentThread.ManagedThreadId
Asked Answered
C

1

12

What would be (the closest) .NET Core 1.0 equivalent for

System.Threading.Thread.CurrentThread.ManagedThreadId 

?

update

As @svick clarified System.Threading.Thread.CurrentThread.ManagedThreadId is at its usual location. Please see the screenshot below. The question is closed. (Still unclear how and when CurrentThread property's System.Threading.Thread instance is initialized to a non-null value (default(System.Threading.Thread) is always == null?) but this is not the subject of this topic.)

enter image description here

update 2

Actually System.Threading.Thread.CurrentThread.ManagedThreadId is available in .NET Core 1.0 application project, which has defined in its project.json:

"frameworks": {
  "netcoreapp1.0": {
  "imports": "dnxcore50"
}

and is missing in .NET Core 1.0 class library project, which has defined in its project.json:

"frameworks": {
  "netstandard1.6": {
   "imports": "dnxcore50"
}

How to make System.Threading.Thread.CurrentThread.ManagedThreadId available in .NET Core 1.0 class library project?

Camelopardalis answered 28/6, 2016 at 15:57 Comment(2)
What you're looking at is the source of the reference assembly (that's why it's in the ref directory and not in src). The actual implementation is in CoreCLR.Spannew
@svick: Thank you, I see it now - ManagedThreadId is implemented using native mode hacking - here is a quoted comment from thread.cs code: "The base implementation of Thread is all native. The following fields should never be used in the C# code. They are here to define the proper space so the thread object may be allocated. DON'T CHANGE THESE UNLESS YOU MODIFY ThreadBaseObject in vm\object.h"Camelopardalis
S
22

It's still the same: System.Threading.Thread.CurrentThread.ManagedThreadId.

The Thread class is in the System.Threading.Thread package, which is included in Microsoft.NETCore.App, but not in NETStandard.Library. This means that Thread will work out of the box in a .Net Core application, but to use it in a .Net Core library, you need to add "System.Threading.Thread": "4.0.0" to "dependencies" in your project.json.

For VS 2017 and .csproj based .NET Core projects, you'd add it to the .csproj:

    <PackageReference Include="System.Threading.Thread" Version="4.0.0" />    
Spannew answered 28/6, 2016 at 18:54 Comment(6)
Silly me. Yes, I have just started to use .NET Core 1.0 yesterday and I have missed System.Threading.Thread.CurrentThread.ManagedThreadId. I will update and I will close my original question.Camelopardalis
I have added update2 clarifying the context of the subject question/issue: question is set back to openCamelopardalis
Yes, adding "System.Threading.Thread": "4.0.0" to the dependencies section of the project.json file solves the subject issue.Camelopardalis
OT: (should I ask the following question separately, will it be accepted at StackOverflow?) Where can I find detailed description of what is included in Microsoft.NETCore.App and what is included in NETStandard.Library? - I wanted to convert my generic/utility .NET Framework 4.0 compatible class library, web service and console application to .NETCore 1.0 to have them running under both MS Windows and Linux. I wanted to keep my current development/conversion in VS2015 but then port the project under VSCode. I don't see on the web any tutorials.Camelopardalis
@Camelopardalis Yeah, I think asking a new question would be the best option, comments are not meant for that.Spannew
OK, it looks like my question has already been posted and has been answered here ".NET Core - solutions, frameworks, imports, runtimes" (#37586398)Camelopardalis

© 2022 - 2024 — McMap. All rights reserved.