0

I want to spawn multiple threads using a ThreadPool based on the available system memory, how can I do that using C#? For example: I want to spawn around 200 threads per GB of available system memory.

I have done this exercise on python where I could use the psutil package to fetch the memory.

 memory = psutil.virtual_memory()

 total_memory = memory.available/1024/1024/1024

 available_memory = round(total_memory)

 print ('Available memory in GB is %s'%available_memory)

I would like to replicate the same on C#.

1 Answers1

1

Based on what you've said you what to do the same thing of the python code but now in C#.

ComputerInfo computerInfo = new ComputerInfo();
double totalMemory = computerInfo.AvailablePhysicalMemory / 1024.0 / 1024.0 / 1024.0;
int availableMemory = (int)Math.Round(totalMemory);
Console.WriteLine("Available memory in GB is " + availableMemory);

Let me know if that's you are looking for