85 days ago · 11 min read2214 words · Tech · hide · Fediverse post

This is a post about a simple concept. In .NET, I want to know how many processors exist on a host/VM. However, as far as I can tell, there's no APIs for that in modern .NET. If you need that information, this post shows the only approach I could come up with, which involves a P/Invoke on some platforms, and parsing files on Linux! If there's a better way, please tell me, I kind of hate what I've had to do here 😅 Why not Environment.ProcessorCount? Hopefully someone is thinking "Why wouldn't you just use Environment.ProcessorCount". After all, it's been available since .NET Framework 2.0! Unfortunately, what this value actually means depends on which version of .NET you're using… .NET Framework—Returns the number of logical processors on the host machine (i.e. exactly what I want 🎉) .NET Core < 6—Returns the number of logical processors on the host machine, but is container aware (to an extent, though it is buggy) .NET Core 6+—Returns the number of logical processors on the host…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town