user4951
user4951

Reputation: 33130

How to determine total unused physical memory in vb.net

I want to limit the number of threads I create based on the amount of free physical memory. For instance I want to stop making new threads once I reach the point that there is only 7GB of real memory left. How would I do so?

Upvotes: 2

Views: 1677

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460208

You can use Devices.ComputerInfo to get the total amount of free physical memory:

Dim info = New Microsoft.VisualBasic.Devices.ComputerInfo()
Dim gb = info.AvailablePhysicalMemory / 1024 / 1024 / 1024
While gb >= 7
    ' start your threads here ... '
    gb = info.AvailablePhysicalMemory / 1024 / 1024 / 1024
End While

Upvotes: 4

Related Questions