3 hours ago · 11 min read2214 words · Tech · hide · 0 comments

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…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.