Hello y'all o/
It's me again.
The following code will show CPU and RAM usage percentage on a pair of label and progress bars.
The code is quite fine and tested. The problem is when I open the solution project file (Which was created on a win10 console) on a win7 similar x64 architecture with a totally same Microsoft Visual Studio 2012 edition software, it start not to syntax error the line:Code:Public Class Form1 Private CPU_Using As New PerformanceCounter() Public Sub New() InitializeComponent() End Sub Private Function CpuId() As String Dim computer As String = "." Dim wmi As Object = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & computer & "\root\cimv2") Dim processors As Object = wmi.ExecQuery("Select * from " & "Win32_Processor") Dim cpu_ids As String = "" For Each cpu As Object In processors cpu_ids = cpu_ids & ", " & cpu.ProcessorId Next cpu If cpu_ids.Length > 0 Then cpu_ids = cpu_ids.Substring(2) Return cpu_ids End Function Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick CPU_Using.CategoryName = "Processor" CPU_Using.CounterName = "% Processor Time" CPU_Using.InstanceName = "_Total" Dim Rounded_CPU_Usage As Double Rounded_CPU_Usage = Math.Round(CPU_Using.NextValue()) CPUvalue.Text = Rounded_CPU_Usage & "%" CPUmeter.Value = CInt(Fix(Rounded_CPU_Usage)) RAMmeter.Value = Math.Round((Val((My.Computer.Info.TotalPhysicalMemory) - Val(My.Computer.Info.AvailablePhysicalMemory)) / Val(My.Computer.Info.TotalPhysicalMemory)) * 100) RAMvalue.Text = RAMmeter.Value & "%" End Sub End Class
But when I run the app, major fault which led to debugging the app appears. (I am away from the mentioned workstation. I will add a photo of the error details ASAP as an edit soon)Code:Rounded_CPU_Usage = Math.Round(CPU_Using.NextValue())
It should be noted that commenting that single particular line will rectify the matter.
I insist, no more related codes and libraries like ones below was imported.
Code:Imports System.Runtime.InteropServices Imports System.ComponentModel




Reply With Quote
