In .NET, you can use the System.Diagnostics namespace to get information about the CPU usage. Here's an example of how you can use it to get the total CPU load and the load of each individual core:
Imports System.Diagnostics
Module Module1
Sub Main()
Dim cpuCounter As New PerformanceCounter("Processor", "% Processor Time", "_Total")
Dim cpuCounterInstances As String() = cpuCounter.RawValue.GetType().GetField("_instances", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.GetField).GetValue(cpuCounter).ToString().Split(CChar("|"))
Dim cpuCounters As New PerformanceCounter("Processor", "% Processor Time") {}
For i As Integer = 0 To cpuCounterInstances.Length - 1
cpuCounters.Add(New PerformanceCounter("Processor", "% Processor Time", cpuCounterInstances(i)))
Next
Console.WriteLine("Total CPU load: {0:P2}", cpuCounter.NextValue())
For i As Integer = 0 To cpuCounters.Length - 1
Console.WriteLine("Core {0} load: {1:P2}", i, cpuCounters(i).NextValue())
Next
Console.ReadLine()
End Sub
End Module
This code creates a PerformanceCounter for the total CPU load and for each individual core. The total CPU load is obtained using the "Processor(_Total)" instance, while the individual core loads are obtained by iterating over the instances returned by the _instances field of the total CPU counter.
The _instances field is not public, so it's accessed using reflection. Note that this may not work in all environments, as it relies on an internal implementation detail of the PerformanceCounter class.
The NextValue() method of each counter is called to retrieve the current CPU load as a percentage. The results are then printed to the console.
Note that the PerformanceCounter class may require elevated privileges to access some performance counters, so you may need to run your application with administrator privileges if you encounter any security exceptions.